//输入的方法; //while函数; //读取完毕; import java.util.Scanner; public class Example2_3 { public static void main(String[] args) { System.out.println("用空格或回车左分隔,输入若干个数\n" + "最后输入0回车作为结束"); Scanner reader = new Scanner(System.in); double sum=0; double x=reader.nextDouble();//读取一个double类型的数; //这个reader类的函数可以有reader.nextInt,reader.neatDouble,reader.nextByte; while (x!=0){//说明下一行还有数字;还没读完; sum+=x; x=reader.nextDouble(); } System.out.printf("sum=%10.5f\n",sum); } }