最高分
This commit is contained in:
parent
7c6c325b73
commit
028ae17647
30
src/ClassScoreAnalyzer.java
Normal file
30
src/ClassScoreAnalyzer.java
Normal file
@ -0,0 +1,30 @@
|
||||
public class ClassScoreAnalyzer {
|
||||
public static void main(String[] args) {
|
||||
// 1. 创建并初始化数组
|
||||
int[] testScores = {85, 92, 78, 95, 88};
|
||||
|
||||
// 2. 使用循环打印所有学生的成绩
|
||||
for (int i = 0; i < testScores.length; i++) {
|
||||
System.out.println("学生" + (i + 1) + "的成绩:" + testScores[i]);
|
||||
}
|
||||
|
||||
// 4. 调用 findHighestScore 方法并打印结果
|
||||
int highestScore = findHighestScore(testScores);
|
||||
System.out.println("班级最高分是:" + highestScore);
|
||||
}
|
||||
|
||||
// 3. 编写 findHighestScore 方法
|
||||
public static int findHighestScore(int[] scores) {
|
||||
if (scores == null || scores.length == 0) {
|
||||
return -1; // 返回-1表示数组为空或null
|
||||
}
|
||||
|
||||
int max = scores[0]; // 假设第一个元素是最大的
|
||||
for (int i = 1; i < scores.length; i++) {
|
||||
if (scores[i] > max) {
|
||||
max = scores[i];
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
2
src/Example22.java
Normal file
2
src/Example22.java
Normal file
@ -0,0 +1,2 @@
|
||||
package PACKAGE_NAME;public class Example22 {
|
||||
}
|
2
src/Example23.java
Normal file
2
src/Example23.java
Normal file
@ -0,0 +1,2 @@
|
||||
package PACKAGE_NAME;public class Example23 {
|
||||
}
|
2
src/GetMax.java
Normal file
2
src/GetMax.java
Normal file
@ -0,0 +1,2 @@
|
||||
package PACKAGE_NAME;public class GetMax {
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user