ordenar numeros java

Solutions on MaxInterview for ordenar numeros java by the best coders in the world

showing results for - "ordenar numeros java"
Sara
02 Jan 2021
1int[] numeros;
2		numeros = new int[3];
3		int con1 = 0, con2 = 0, num;
4		Scanner sc;
5		sc = new Scanner(System.in);
6
7		for (int i = 0; i < numeros.length; i++) {
8			System.out.println("Introduce 3 numeros:");
9			num = sc.nextInt();
10			numeros[i] = num;
11		}
12		System.out.println();
13		System.out.println("estos son tus numeros: ");
14		for (int i = 0; i < numeros.length; i++) {
15			System.out.print(numeros[i] + " ");
16		}
17		
18		for (int i = 0; i < numeros.length; i++) {
19			
20			for (int j = 0; j < numeros.length - i - 1; j++) {
21				con1++;
22				if (numeros[j] > numeros[j + 1]) {
23					con2++;
24					int aux;
25					aux = numeros[j];
26					numeros[j] = numeros[j + 1];
27					numeros[j + 1] = aux;
28					
29				}
30
31			}
32		}
33		System.out.println();
34		System.out.println("ordenados: ");
35		for (int i = 0; i < numeros.length; i++) {
36			System.out.print(numeros[i] + " ");
37		}
38