import java.util.Scanner;
public class Example {
public static void main (String args[]){
System.out.println("请输入若干个数,每输入一个数回车确认");
System.out.println("最后输入数字0结束输入操作");
Scanner reader =new Scanner(System.in);
double sum=0;double x=reader.nextDouble();
while(x!=0){
sum=sum+x;
x=reader.nextDouble();
}
System.out.println("sum="+sum);
}
}
运行结果:
请输入若干个数,每输入一个数回车确认
最后输入数字0结束输入操作123456
123789.88
14.5896
0
sum=247260.4696