代码如下:
import java.util.Scanner;
public class sum {
public static void main(String[]args){
int nextValue;
int sum=0;
Scanner kbInput = new Scanner(System.in);
kbInput.useDelimiter("\s");
while(kbInput.hasNextInt())
{
nextValue = kbInput.nextInt();
sum += nextValue;
}
System.out.printf("Sum: %d",sum);
kbInput.close();
}
}
运行结果: