Discuss / Java / 练习

练习

Topic source
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        int[] ns = { 28, 12, 89, 73, 65, 18, 96, 50, 8, 36 };
        for(int i = 0; i < ns.length;i++) {
        	for(int j = 0; j < ns.length-1-i; j++) {
        		if(ns[j] < ns[j+1]) {
        			int tmp = ns[j];
        			ns[j] = ns[j+1];
        			ns[j+1] = tmp;
        		}
        	}
        	
        }
        System.out.println(Arrays.toString(ns));
    }
}

  • 1

Reply