我很难理解这项任务要求我做什么。我是一个绝对的初学者,学习了几个星期的 Java/编程,这对我来说很难。因此,对于标题中没有非常具体的问题,我们深表歉意。
如果有人可以向我解释,我将非常感激,也许有一些示例代码(我不是要求人们为我完成任务,我只是觉得这样更容易理解)所以我可以知道该怎么做。
谢谢你。
求和规范:
该程序从命令行获取输入。
The first input is K, an integer, followed by an arbitrary number a_1, ..., a_N of floating-point numbers.
If K=0, then N is output.
If K > 0, then the a_i are grouped in groups of size K, inside the groups the numbers are multiplied, and all the products are added, yielding the output.
If K < 0, then the summation sums up the reciprocal values of the products.
In the special case K=1 the output thus is a_1 + ... + a_N.
In the case K=-1 the output is 1/a_1 + ... + 1/a_N.
There are two error cases:
If no command-line argument is given, then error-code 1 is to be returned.
If K < 0, and one of a_i = 0, then error-code 2 is to be returned.
In both cases there must be no output.
The return-code of a program is set via System.exit(code);
请注意,程序的返回码是在命令行中通过 echo $? 获得的。绝不能有任何其他输出。也不允许额外的空格或换行符。
以下是无错误情况下的示例:http: //pastebin.com/F2uz262v