为啥第三个for循环没能实现排序呀,或者大家有其他实现排序的方法吗
import java.util.Arrays; public class HelloWorld { public static void main(String[] args) { HelloWorld hello = new HelloWorld(); int[] rank = {89, -23, 64, 91, 119, 52, 73}; hello.getArrays(rank); }//定义方法完成成绩排序并输出前三名的功能 public int[] getArrays(int []rank) { int max3=rank[0]; int max2=rank[0]; int max1=rank[0]; int[] nums = {1, 2, 3}; for (int i = 0; i < rank.length-1; i++) { if (rank[i] > 1 && rank[i] < 100) { if (rank[0] < rank[i]) { max1 = rank[i]; } } } for (int i = 0; i < rank.length-1; i++) { if (rank[0] <rank[i]&&rank[i]<max1) { if (rank[i] > 1 && rank[i] < 100) { max2 =rank[i]; } } } for(int i=1;i<rank.length;i++){ if(rank[i]>rank[i]){ max3=rank[i]; } } nums[0]=max1;nums[1]=max2;nums[2]=max3; System.out.println(Arrays.toString(nums)); return nums; } }
然后输出的是91 89 89?