程序代码:
import java.util.Scanner; public class Calculate { public static void main(String[] args) { System.out.println("请输入要计算的整数个数:"); int count = new Scanner(System.in).nextInt(); int sum = 0; for (int i = 1; i < count + 1; i++) { System.out.println("请输入第" + 1 + "个整数:"); sum += new Scanner(System.in).nextInt(); } System.out.println("和:" + sum + "\r\n平均:" + sum * 1.0 / count); } }
假如人生没有梦想,和咸鱼有什么区别!