求和

import java.util.Scanner;
public class Sum {
public static void main(String[] args) {
// TODO Auto-generated method stub
int nextValue, sum=0;
Scanner sc = new Scanner(System.in);
sc.useDelimiter("\s");
while(sc.hasNextInt())
{
nextValue = sc.nextInt();//读取从键盘输入的数
sum += nextValue;
}
sc.close();
System.out.println("Sum:" + sum);
System.out.printf("Sum: %d",sum);
}
}

posted @ 2016-03-28 19:36  14软三2014330326杨佳  阅读(117)  评论(0编辑  收藏  举报