第三次作业

public class TestScanner {

/**
 * @param args
 */
public static void main(String[] args) {
	// TODO Auto-generated method stub依次从键盘读取若干整数求和输出
	int nextValue;
	int sum = 0;
	Scanner sr = new Scanner(System.in); //创建从键盘读取数据的Scanner
	sr.useDelimiter("\s");//设置空格为分隔符
	while(sr.hasNextInt()){//判断是否有整数可度
	nextValue = sr.nextInt();//读取从键盘输入的一个整数
    sum +=nextValue;
	}
    System.out.println("Sum"+sum);
    sr.close();//关闭流对象
	

}

}

原文地址:https://www.cnblogs.com/yinxinlei/p/5333694.html