Discuss / Java / 思考题

思考题

Topic source

风之子

#1 Created at ... [Delete] [Delete and Lock User]
import java.util.Arrays;

public class Array {
  public static void main(String[] args) {
    int[] ns = { 28, 12, 89, 73, 65, 18, 96, 50, 8, 36 };
    // 排序前:
    System.out.printf("降序排序前:%s", Arrays.toString(ns));
    // 降序排序:
    for (int i = 0; i < ns.length - 1; i++) {
      for (int j = i + 1; j < ns.length; j++) {
        if (ns[i] < ns[j]) {
          int tem = ns[i];
          ns[i] = ns[j];
          ns[j] = tem;
        }
      }
    }
    System.out.printf("降序排序后:%s", Arrays.toString(ns));
  }
}

  • 1

Reply