数组赋值 解决 方法:边声明边赋值 int[]score={89,79,76; int[]score new int[]89,79,76}; 方法2:动态地从键盘录入信息并赋值 Scanner input new Scanner(System.in); for(int i=0;i<30;i++){ score[i]input.nextlnt();
数组赋值 方法1: 边声明边赋值 方法2:动态地从键盘录入信息并赋值 解决 int[ ] score = {89, 79, 76}; Scanner input = new Scanner(System.in); for(int i = 0; i < 30; i ++){ score[i] = input.nextInt(); } int[ ] score = new int[ ]{89, 79, 76};
使用数组求平均值 4 对数据进行处理:计算5位学生的平均分 int[]score={60,80,90,70,85; 访问数组成员:使 用“标识符下标” double avg; avg =(score[0]score[1]score[2]score[3]score[4])/5; int[]score={60,80,90,70,85}; int sum=0; 数组的1 ength/属性 60 double avg; 80 成 for(int index 0;index score.length;index++){ 90 sum sum score[index]; 70 avg sum score.length; 访问成员 85
使用数组求平均值 60 80 90 70 85 int [ ] score = {60, 80, 90, 70, 85}; double avg; avg = (score[0] + score[1] + score[2] + score[3] + score[4])/5; int [ ] score = {60, 80, 90, 70, 85}; int sum = 0; double avg; for(int index = 0; index < score.length; index++){ sum = sum + score[index]; } avg = sum / score.length; 成 绩 单 访问数组成员:使 用“标识符[下标]” 访问成员 数组的length属性 4 对数据进行处理:计算5位学生的平均分