慕哥5794780
2015-07-23 20:56
import java.util.Arrays;
public class Score {
public static void main(String[] args) {
int[] scores = {89, 23, 64, 91, 119, 52, 73};
Arrays.sort(scores);
Score hello = new Score();
hello.top(scores);
}
public void top(int[] scores) {
System.out.print("考试成绩的前三名;");
int num = 0;
for (int i = scores.length - 1; i > 0; i--) {
if (scores[i] > 0 && scores[i] < 100) {
num++;
if (num > 3) {
break;
}
System.out.print(scores[i]);
}
}
}
}
修订版:
import java.util.Arrays;
public class Score {
public static void main(String[] args) {
int[] scores = {89, 23, 64, 91, 119, 52, 73};
Arrays.sort(scores);
Score hello = new Score();
hello.top(scores);
}
public void top(int[] scores) {
System.out.print("考试成绩的前三名;");
int num = 0;
for (int i = scores.length - 1; i > 0; i--) {
if (scores[i] > 0 && scores[i] < 100) {
num++;
if (num > 3) {
break;
}
System.out.print(scores[i]);
}
}
}
}
Java入门第一季(IDEA工具)升级版
1165177 学习 · 17581 问题
相似问题