第三次JAVA作业
package pro;
import java.util.Scanner;
public class number {
public static void main(String[]args){
//从键盘读取若干整数并求和
int nextValue;
int sum=0;
Scanner num = new Scanner(System.in);
num.useDelimiter("\\s");
while(num.hasNextInt())
{
nextValue = num.nextInt();//读取从键盘输入的数
sum += nextValue;
}
System.out.printf("Sum: %d",sum);
num.close();
}
}
import java.util.Scanner;
public class number {
public static void main(String[]args){
//从键盘读取若干整数并求和
int nextValue;
int sum=0;
Scanner num = new Scanner(System.in);
num.useDelimiter("\\s");
while(num.hasNextInt())
{
nextValue = num.nextInt();//读取从键盘输入的数
sum += nextValue;
}
System.out.printf("Sum: %d",sum);
num.close();
}
}
![](https://images2015.cnblogs.com/blog/903581/201603/903581-20160328173252113-1325869669.png)