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); } }
运行结果: