//定义方法完成成绩排序并输出前三名的功能public class HelloWorld { public static void main(String[] args) { int[] arr1={89,-23,64,91,119,52,79}; HelloWorld arr=new HelloWorld(); arr.array(arr1); } public static void array(int[] arr1){ Arrays.sort(arr1); System.out.println("前三名的分数是:"); for (int i=0;i<arr1.length;i++){ for (int j=0;j<arr1.length-1-i;j++){ if (arr1[j]<arr1[j+1]){ int temp=arr1[j+1]; arr1[j+1]=arr1[j]; arr1[j]=temp; } } } for (int i=0;i<arr1.length;i++){ if (i<3){ System.out.print(arr1[i]+"\t"); } } }}这简直是Bug啊
添加回答
举报
0/150
提交
取消