import java.util.Arrays;
/*要求:
1、 考试成绩已保存在数组 scores 中,数组元素依次为 89 , -23 , 64 , 91 , 119 , 52 , 73
2、 要求通过自定义方法来实现成绩排名并输出操作,将成绩数组作为参数传入
3、 要求判断成绩的有效性( 0—100 ),如果成绩无效,则忽略此成绩*/
public class HelloWorld {
public static void main(String[] args) {
//输入成绩scores
int[] scores = new int[]{89,-23,64,91,119,52,73};
//创建对象,对象名称hello
System.out.println("考试成绩的前三名为:");
HelloWorld hello = new HelloWorld();
hello.getArrays(scores);
}
public void getArrays(int[] scores){
int count = 0;
Arrays.sort(scores);
for(int i = scores.length - 1;i>=0 && count<3;i--){//循环 遍历整个数组
if(scores[i]>0 && scores[i]<100){
System.out.println(scores[i]);
count++;
}else{
continue;
}
}
}
}
执月未央丶暮色断
2014-11-03
1 回答
举报
0/150
提交
取消