我想将数组的每个元素写入一个文本文件。例如下面将更清楚地演示
String[] Name = {"Eric","Matt","Dave"}
Int[] Scores = {[45,56,59,74],[43,67,77,97],[56,78,98,87]}
double[] average = {45.7,77.3,67.4}
我想要文本文件中的以下内容
Student Eric scored 45,56,59,74 with average of 45.7
Student Matt scored 43,67,77,97 with average of 77.3
Student Dave scored 56,78,98,87 with average of 67.4
我创建了输出文件
PrintStream output = new PrintStream(new File("output.txt"));
我使用了一个 for 循环
for(int i =0;i<=Name.length;i++){
output.println("Student " + Name[i] + " scored " + Scores[i] + " with average of " + average[i]);
}
但这没有用。请帮忙。