JAVA学习笔记(三)
package javazuoye;
import java.util.Scanner;
public class numsum {
public static void main(String[]args){
int nextValue;
int sum=0;
Scanner GInput = new Scanner(System.in);
GInput.useDelimiter("\\s");
while(GInput.hasNextInt())
{
nextValue = GInput.nextInt();
sum += nextValue;
}
System.out.printf("Sum: %d",sum);
GInput.close();
}
}
import java.util.Scanner;
public class numsum {
public static void main(String[]args){
int nextValue;
int sum=0;
Scanner GInput = new Scanner(System.in);
GInput.useDelimiter("\\s");
while(GInput.hasNextInt())
{
nextValue = GInput.nextInt();
sum += nextValue;
}
System.out.printf("Sum: %d",sum);
GInput.close();
}
}