我很难理解这个任务要求我做什么。我是一个完全的初学者,几个星期的学习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
发布于 2013-11-09 20:36:49
您将在这里找到命令行参数:
public static void main(String args[]) {
// ^ these are the command line arguments所以要得到K
int K = Integer.parseInt(args[0]);但实际上,您不应该这样写它,因为这是Java,Java变量应该以小写字母开头。
int k = Integer.parseInt(args[0]);首先,让我们讨论一下k=0的情况。我们必须测试k是否为0:
if(k == 0) {如果是,则N是附加参数的数目,即
int numberOfAdditionalArguments = args.length - 1;然后我们打印它(之后没有断线,就像上面写的!)
System.out.print(numberOfAdditionalArguments);然后关闭}块
}我想这足以让你开始工作。
https://stackoverflow.com/questions/19882153
复制相似问题