gpt4 book ai didi

java - 更改输出编号

转载 作者:行者123 更新时间:2023-12-01 21:34:19 26 4
gpt4 key购买 nike

如何实现第一个学号为 1 而不是 0?我尝试将 i 更改为 1。

// Get grades
getGrades(scores, grades);

// Display results
for (int i = 0; i < scores.length; i++) {
System.out.println("Student " + i + " score is " +
scores[i] + " and grade is " + grades[i]);
}

现在的输出如下:

Enter the nubmer of students: 3

Enter 3 scores: 23 45 67

Student 0 score is 23 and grade is F

Student 1 score is 45 and grade is C

Student 2 score is 67 and grade is A

最佳答案

你的代码很好,只需将你的打印更改如下:

System.out.println("Student " + (i + 1) + " score is " + scores[i] + " and grade is " + grades[i]);

(i + 1) 将输出您想要的偏移量。

关于java - 更改输出编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37102646/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com