import java.util.Arrays; public class Hergiu{ public static void main(String[] args){ Hergiu hg = new Hergiu(); int[] scores = {89,-23,64,91,119,52,73}; int[] Sott = hg.getOtt(scores); System.out.println(Arrays.toString(Sott)); } public int[] getOtt(int[] getScores){ int[] outScores = new int[2]; Arrays.sort(getScores); int j = 0; for(int i=getScores.length-1;i>=0;i--){ if(getScores[i]>100){ continue; } outScores[j] = getScores[i]; j++; if(j>3){ break; } } return outScores; } }
int[] outScores = new int[2];
这定义两个 ,后面那个j看看最多几了。自己eclipse调调