大神們 可以幫我看看有什么問(wèn)題嗎?結(jié)果是52 64 73 不是正確答案
package Chapter8;
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("Top 3:");
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ? hello.getTop3(scores);
? ? ? ??
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績(jī)排序并輸出前三名的功能
? ? public void getTop3(int[] scores){
? ? ? ? Arrays.sort(scores);
? ? ? ? int num=0;
? ? ? ? for (int i=0;i<scores.length;i++){
? ? ? ? ? ? if (scores[i]<0||scores[i]>100){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? ? ? num++;
? ? ? ? ? ? if (num>3){
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? }
? ? }
? ??
? ??
? ??
? ??
? ??
? ??
? ??
? ??
? ??
}
2016-07-21
? ? for (int i=0;i<scores.length;i++)這里面要使用倒序遍歷,從scores.length-1到0,方便從大到小取值
2016-07-21
for(int i=score.length-1;i>=0;i--)