2 回答
TA贡献1852条经验 获得超1个赞
请将您的代码修改为:
public class Main {
public static void main(String[] args) {
try {
FileWriter fw = new FileWriter(new File("F://test.txt"));
Scanner sc = new Scanner(System.in);
int students = 2;
double[] doubleAVG = new double[students];
char[] charGRADE = new char[students];
double avg = 0.0;
char gradeLetter;
String FirstName = "";
String LastName = "";
for (int count = 0; count < students; count++) {
System.out.println("Enter average :");
avg = sc.nextDouble();
System.out.println("Enter grade :");
gradeLetter = sc.next().charAt(0);
System.out.println("Enter First Name :");
FirstName = sc.next();
System.out.println("Enter Last Name :");
LastName = sc.next();
doubleAVG[count] = avg;
charGRADE[count] = gradeLetter;
fw.write("This is the grade of: " + FirstName + " " + LastName + " ");
fw.write(String.valueOf(doubleAVG[count]) + " ");
fw.write(charGRADE[count] + System.lineSeparator());
}
fw.close();
sc.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
控制台输入:
Enter average :
70.45
Enter grade :
B
Enter First Name :
John
Enter Last Name :
Johnson
Enter average :
90.47
Enter grade :
A
Enter First Name :
Michael
Enter Last Name :
Jordan
在test.txt中:
This is the grade of: John Johnson 70.45 B
This is the grade of: Michael Jordan 90.47 A
TA贡献1995条经验 获得超2个赞
您是否知道 java Serialize 方法(学),它创建了您在类文件中拥有的所有数据结构及其对象的 xml 文件,使其中的嵌套结构看起来像特定时间点的对象,就像原始 xml 一样?这可能是由于 java 在 5 种确切的本机数据类型上中继,而对象只是这些数据类型的集合。看看上面的评论以及 Stackoverflow 答案的链接,我只是向您解释了一些有关机制的信息。
添加回答
举报