已知7门功课成绩,功课名称,要求输出
语文=67
数学=56
等等,最好还有计算总分,平均分本来功课名称想用数组,好像数组里的值可以为int型,但不能为字符串汉字。public class test{ public static void main(String[] args) {
int arr []={67,56,24,75,52,89,95};
String km=("语文数学英语物理化学历史地理");
}
}
语文=67
数学=56
等等,最好还有计算总分,平均分本来功课名称想用数组,好像数组里的值可以为int型,但不能为字符串汉字。public class test{ public static void main(String[] args) {
int arr []={67,56,24,75,52,89,95};
String km=("语文数学英语物理化学历史地理");
}
}
public class OutputScores {
public static void main(String args[]){
String[] courseStr = {"语文", "数学", "英语", "物理", "化学", "历史", "地理"};
int[] courseScores = {67,56,24,75,52,89,95};
String output = "";
int 总分 = 0;
int 平均分 = 0;
for (int i=0; i<courseStr.length; i++){
output += courseStr[i] +": "+ courseScores[i] +"\n";
总分 += courseScores[i];
}
平均分 = 总分/courseStr.length;
output += "总分:"+ 总分 +"\n平均分: "+ 平均分;
System.out.print(output);
}
}语文: 67
数学: 56
英语: 24
物理: 75
化学: 52
历史: 89
地理: 95
总分:458
平均分: 65
数组里的元素是什么类型可以自己定义的,你想让它是什么就可以是什么