求指教,結(jié)果怎么一直是排序后的數(shù)組
import java.util.Arrays;
public class HelloWorld {
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ?int[] scores={89,-23,64,91,119,52,73};
? ? ?HelloWorld hello=new HelloWorld(); ??
? ? ?hello.top3(scores);?
? ? ? ?
? ? }
? ??
? ? //定義方法完成成績(jī)排序并輸出前三名的功能
? public void top3(int[] scores){
? ? ? ? int count=0
? ? ? ? Arrays.sort(scores);
? ?System.out.println("考試前三名為:");
? ? ? ? for(int i=scores.length-1;i>=0;i--){
? ? ? ? ? ? if(scores[i]<0 || scores[i]>100){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?continue;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? count++;
? ? ? ? ? ? ? ? ? ?if(count>3){
? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ?System.out.println(scores[i]);
? ? ? ? }
? ? ? ?
? ? }
? ??
? ??
2015-11-16
問題在于continue使用的有問題,不應(yīng)該使用;你給的數(shù)組數(shù)據(jù)只有兩個(gè)不符合if條件,導(dǎo)致后面的break一直沒有執(zhí)行;
2015-11-18
自己回答,int count=0缺了個(gè);