求大神解決
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ? int[] scores={89,-23,64,91,119,52,73};
? ? ? ? ?hello.grades(scores);
? ? ? ? System.out.println("考試成績的前三名為:");
? ? ? ??
? ? ? ??
? ? }
? ??
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ??
? ? public void grades(int []scores ){
? ? ? ? Arrays.sort(scores);
? ? ? ? int num=0;
? ? ? ? for(int i=scores.lenth-1;i>=0;i--){
? ? ? ? ? ? if(scores[i]<0||scores[i]>100){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? ? ? ? ? num++;
? ? ? ? ? ? if(num>3){
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? ? ? }
? ? }?
}
? ??
? ??
? ??
? ??
? ??
? ??
}
2016-05-16
好好修改就可以、學(xué)會自己調(diào)試錯誤??!
2016-05-06
hello.grades(scores)都調(diào)用方法了,就是這段代碼執(zhí)行了方法的代碼,就直接輸出前3名成績了。System應(yīng)該在它的前面就行輸出才可以。新手共勉!
2016-04-27
在你寫的方法里,for循環(huán)的這句“int i=scores.lenth-1”的length拼錯了,少了"g"。
還有就是,在main函數(shù)里,“System.out.println("考試成績的前三名為:")”這條語句應(yīng)該在“hello.grades(scores);”之前,才能符合題目要求的輸出格式。
2016-04-27
因為前面排序是通過升序排序的方法 然后在是通過?for(int i=scores.lenth-1;i>=0;i--)倒序進行判斷,所以滿足條件?if(scores[i]<0||scores[i]>100)的最前三個是91,89,73
2016-04-26
if(num>3){
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
這個地方的判斷喲什么作用嗎》?