Java中求和与平均值
Java中求和与平均值
操作方法
- 01
建立一个ss类
- 02
public class ss { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); System.out.println("你想输入几个数字:"); int count = input.nextInt(); int num[] = new int[count]; int sum = 0; double avg = 0; System.out.print("输入的数字为:"); for (int i = 0; i < num.length; i++) { num[i] = input.nextInt(); sum += num[i]; } avg = sum / count; System.out.println("它们的和是:" + sum); System.out.println("它们的平均值是:" + avg); } }
赞 (0)