【发布时间】:2014-09-14 22:49:06
【问题描述】:
几乎我必须添加用户从数组输入的数字。所以这就是我所拥有的。
Scanner input=new Scanner(System.in);
int[] array1=new int[5];
System.out.print("Enter the first number.");
array1[0]=input.nextInt();
System.out.print("Enter the second number.");
array1[1]=input.nextInt();
System.out.print("Enter the third number.");
array1[2]=input.nextInt();
System.out.print("Enter the fourth number.");
array1[3]=input.nextInt();
System.out.print("Enter the fifth number.");
array1[4]=input.nextInt();
System.out.println("The grand sum of the numbers you entered is :"+(array1));
【问题讨论】:
-
如果您使用的是 java8,这里是快速解决方案。 stackoverflow.com/questions/4550662/…
-
对于结构上的任何求和都认为“循环”:)
-
@Robert 我发布了我的答案,并解释了很多。让我知道你是怎么过的:)
标签: java arrays eclipse addition