Scanner拓展

package com.liu.scanner;

import java.util.Scanner;

public class Demo5 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double sum = 0;
for (int i =0; ; i++) {
if (scanner.hasNextDouble()){
double x = scanner.nextDouble();
sum = sum+x;
System.out.println("您输入第"+(i+1)+"个数字,当前结果sum="+sum);
}else{
System.out.println(i+"个数的和为"+sum);
System.out.println(i+"个数的平均值为"+sum/i);
break;//不是用return
}
}
scanner.close();
}
}

Scanner拓展

上一篇:电脑 直接下载cyida deb


下一篇:适配器模式