清晨得曙光
2016-12-11 23:22
就是成绩用Scanner输入的
无法解析的时候可以看看是不是少了大括号什么的
import java.util.*;
public class HelloWorld {
//完成 main 方法
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// ArrayList<Integer> input = new ArrayList<>();
System.out.println("How many scores: ");
if (sc.hasNextInt()){
int number = sc.nextInt();
int[] inputScore = new int[number];
for (int i = 0; i < number; i ++){
System.out.println("Input score:");
inputScore[i] = sc.nextInt();
}
}
top3(inputScore);
// while (sc.hasNextInt()){
// input.add(sc.nextInt());
// }
// int[] scores = new int[]{89 , -23 , 64 , 91 , 119 , 52 , 73};
// top3(scores);
}
//定义方法完成成绩排序并输出前三名的功能
public static int[] top3(int[] scores){
int[] result = new int[3];
int count = 0;
Arrays.sort(scores);
for (int i = scores.length - 1; count < 3 && i >= 0; i --){
if (scores[i] >= 0 && scores[i] <= 100){
result[count++] = scores[i];
}
}
System.out.println(Arrays.toString(result));
return result;
}Java入门第一季(IDEA工具)
1168264 学习 · 18754 问题
相似问题
回答 1
回答 8