Java第三次实验

import java.util.Scanner;


public class Text {

    public static void main(String[] args) {

        int nextValue;
        int sum = 0;
        Scanner kbIntput = new Scanner(System.in);
        kbIntput.useDelimiter("\\s");
        while(kbIntput.hasNextInt())
        {
            nextValue = kbIntput.nextInt();
            sum+=nextValue;
        }
        kbIntput.close();
        System.out.println("Sum:"+sum);
        System.out.printf("Sum:%d",sum);
    }

}

运行结果:

posted @ 2016-03-28 19:08  Gentleman`  阅读(161)  评论(0编辑  收藏  举报