各位大神,求看看哪里错了
明明好仔细的做了一遍...
2015-03-28
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import java.util.Arrays; public class HelloWorld { //完成 main 方法 public static void main(String[] args) { int [] scores={ 89 ,- 23 , 64 , 91 , 119 , 52 , 73 }; //成绩数组 System.out.println( "考试成绩的前三名为:" ) ; HelloWorld hello= new HelloWorld(); //创建一个对象对象名为Hello hello.showTop3(scores); //调用方法,传人成绩数组 } //定义方法完成成绩排序并输出前三名的功能 public void showTop3( int [] scores){ Arrays.sort(scores); //使用Arrays.sort()方法实现数组排序 int num = 0 ; //保持有效的成绩数量 for ( int i= scores.length- 1 ;i>= 0 ;i--){ //倒序遍历数组中的每一个元素 if (scores[i]< 0 ||scores[i]> 100 ){ //判断程序的有效性 continue ; //如果成绩无效,则跳出本次循环,忽略此成绩 } num++; //有效成绩加1 if (num> 3 ){ //判断有效成绩数量 break ; //如果有小成绩大于3,则结束循环,只输出成绩前三名 } System.out.println(scores[i]); //依次输出前三名 } } } |
我把我改过的给你贴上 你自己对比一下
举报