📜  ordenar numeros java 代码示例

📅  最后修改于: 2022-03-11 14:52:22.995000             🧑  作者: Mango

代码示例1
int[] numeros;
        numeros = new int[3];
        int con1 = 0, con2 = 0, num;
        Scanner sc;
        sc = new Scanner(System.in);

        for (int i = 0; i < numeros.length; i++) {
            System.out.println("Introduce 3 numeros:");
            num = sc.nextInt();
            numeros[i] = num;
        }
        System.out.println();
        System.out.println("estos son tus numeros: ");
        for (int i = 0; i < numeros.length; i++) {
            System.out.print(numeros[i] + " ");
        }
        
        for (int i = 0; i < numeros.length; i++) {
            
            for (int j = 0; j < numeros.length - i - 1; j++) {
                con1++;
                if (numeros[j] > numeros[j + 1]) {
                    con2++;
                    int aux;
                    aux = numeros[j];
                    numeros[j] = numeros[j + 1];
                    numeros[j + 1] = aux;
                    
                }

            }
        }
        System.out.println();
        System.out.println("ordenados: ");
        for (int i = 0; i < numeros.length; i++) {
            System.out.print(numeros[i] + " ");
        }