Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ejerciciosJava;
- import java.util.Scanner;
- public class OrdenarNúmeros {
- public static void main(String args[]) {
- int contador = 0, num, a = 0, i, j;
- int[] numeros = new int[5];
- Scanner teclado = new Scanner(System.in);
- do {
- System.out.println("Introduzca valores (0 para finalizar): ");
- num = teclado.nextInt();
- if (num != 0) {
- numeros[contador] = num;
- contador++;
- }
- } while (num != 0);
- for (i = 0; numeros.length > i; i++) {
- for (j = 0; numeros.length > j; j++) {
- if (numeros[j] < numeros[j + 1]) { //JUSTO AQUÍ ME DA EL ERROR!!
- a = numeros[j];
- numeros[j] = numeros[j + 1];
- numeros[j+ 1] = a;
- }
- }
- }
- for (i = 0; i < numeros.length; i++) {
- System.out.print(numeros[i] + ",");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement