实际上我是这个小组的新手,也是 Java 的新手,我想知道如何通过控制台传递数组参数,我最终编程如下:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Average
{
public static void main(String []args)
{
int numbers[];
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
numbers =Integer.parseInt( br.readLine());
}
catch(NumberFormatException ne)
{
System.out.println("Invalid input: " + ne);
System.exit(0);
}
catch(IOException ioe)
{
System.out.println("I/O Error: " + ioe);
System.exit(0);
}
System.out.println(methodAverage());
}
public static int methodAverage(int...numbers)
{
int sum=0;
int avg=0;
for(int x:numbers)
{
sum+=x;
avg=sum/numbers.length;
return avg;
}
}
}
错误是
Average.java:13: error: incompatible types
numbers =Integer.parseInt( br.readLine());
^
required: int[]
found: int
1 error
我知道那会来,但我只是试过
所以我只想知道如何通过控制台传递这些数字?