package com.liu.arrray; import java.util.Scanner; public class Demo01 { public static void main(String[] args) { //数组例子的练习(计算十个同学的总成绩和平均成绩) Scanner scanner=new Scanner(System.in); int[] nums; int sum=0; int average; nums=new int[10]; System.out.println("输入十个同学的成绩:"); for (int i = 0; i <10; i++) { nums[i]=scanner.nextInt(); } for (int i = 0; i <10; i++) { System.out.println("nums["+i+"]="+nums[i]); sum=nums[i]+sum; } average=sum/10; System.out.println("sum="+sum+";average="+average); } }
基于Java的数组小练习
最新推荐文章于 2024-08-16 23:08:28 发布