sort int Array Ascending - Java java.lang

Java examples for java.lang:int Array

Description

sort int Array Ascending

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int[] num = new int[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        sortArrayAscending(num);/*from  www .j  a v a 2  s  .c  o  m*/
    }

    public static void sortArrayAscending(int[] num) {
        int j;
        boolean flag = true;
        int temp;
        while (flag) {
            flag = false;
            for (j = 0; j < num.length - 1; j++) {
                if (num[j] > num[j + 1]) {
                    temp = num[j];
                    num[j] = num[j + 1];
                    num[j + 1] = temp;
                    flag = true;
                }
            }
        }
    }
}

Related Tutorials