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://i-blog.csdnimg.cn/blog_migrate/c2c7e14700bc8021f6e1a0672f7d7cee.png)