大神來求解
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();
??????? int[] scoreRank = hello.rank(scores);
??????? System.out.println(Arrays.toString(scoreRank));
?????? ?
??? }
?? ?
??? //定義方法完成成績排序并輸出前三名的功能
??? public int[] rank(int[] scores) {
??????? int[] scoreRank = new int[3];
??????? Arrays.sort(scores);
??????? int j = 0;
??????? for (int i = scores.length - 1; i <= scores.lenght - 3; i--) {
??????????? scoreRank[j] = scores[i];
??????????? j++;
??????? }
??????? return scoreRank;
??? } //用來求數(shù)組scores中最大的三個(gè)數(shù)。for循環(huán)有點(diǎn)問題,可我看不出來,幫我看看!
2016-03-12
你循環(huán)里的
第一:scores.lenght--->出問題了
第二:結(jié)果出來都是零
你自己還是看看文檔吧