不知道為什么輸不出結(jié)果
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ??
? ? ? ? double arr[] = {89,-23,64,91,119,52,73};
? ? ? ? HelloWorld hello = new HelloWorld();
? ? ? ? hello.GetGrade(arr);
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void GetGrade(double array[]){
? ? ? ? int count=0;
? ? ? ? Arrays.sort(array);
? ? ? ? for(int i=array.length-1;i<0;i--){
? ? ? ? ? ? while(count<3){
? ? ? ? ? ? ? ? if(array[i]>=0&&array[i]<=100){
? ? ? ? ? ? ? ? System.out.println(""+array[i]);
? ? ? ? ? ? ? ? count++;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? }
? ? }
2015-07-25
非常感謝你提醒我了,改成這樣也可以,不過我覺得上面那個i>array.length-3不太合適,因為并不能保證數(shù)組里的前3位成績都是在[0-100]里面的,共勉共勉!
2015-07-25
你代碼里的i<0就是一個邏輯錯誤了,還有你壓根不需要在搞個while循環(huán)