作业(2)
1 package com.aila; 2 3 public class ailale { 4 5 public static void main(String[] args) { 6 int[] arr = {1,5,6,7,9,8,3,0,2,4}; 7 for(int i = 0;i < arr.length;i++) { 8 for(int j = i + 1;j < arr.length;j++) { 9 if(arr[i] < arr[j]) { 10 int temp = arr[i]; 11 arr[i] = arr[j]; 12 arr[j] = temp; 13 } 14 } 15 16 } 17 for(int i : arr) 18 System.out.println(i); 19 } 20 21 }
1 package com.aila; 2 3 public class ailala { 4 public static void main(String[] args) { 5 int[] arr = {1,5,6,7,9,8,3,0,2,4}; 6 for(int i = 0;i < arr.length;i++) { 7 for(int j = 0;j < arr.length - 1 -i;j++) { 8 if(arr[j] < arr[j + 1]) { 9 int temp = arr[j]; 10 arr[j] = arr[j + 1]; 11 arr[j + 1] = temp; 12 } 13 } 14 15 } 16 for(int i : arr) 17 System.out.println(i); 18 } 19 20 }