import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;
public class Ejercicio{
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static String leer(String message) { String s;
try { System.out.print(message);
s = br.readLine();
} catch (IOException ex) { System.out.println("Hubo un error de lectura, vuelva a intentar"); s = null;
}
if (s == null) { s = leer(message);
}
return s;
}
public static Integer leerInteger(String message) { Integer d;
try { d = Integer.parseInt(leer(message));
} catch (NumberFormatException ex) { System.out.println("Valor incorrecto vuelva a intentar"); d = null;
}
if (d == null) { d = leerInteger(message);
}
return d;
}
public static Integer leerInteger_1_50(String message) { Integer d = leerInteger(message);
if (d < 1 || d > 50) { System.out.println("Numero fuera de rango.\nIntroduzca solo números entre 1 y 50"); d = leerInteger_1_50(message);
}
return d;
}
public static int[] leerArreglo() { int[] valores = new int[10];
for (int i = 0; i < valores.length; i++) { valores[i] = leerInteger_1_50("Introduzca el valor " + (i + 1) + ": "); }
return valores;
}
public static void ordenamientoBurbuja(int[] valores) { for (int i = valores.length - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (j + 1 <= i && valores[j] > (valores[j + 1])) { int aux = valores[j];
valores[j] = valores[j + 1];
valores[j + 1] = aux;
}
}
}
}
public static Integer getRandomNumber(int min, int max) { return new Random().nextInt(max - min + 1) + min;
}
public static void main(String[] args) { int[] valores = leerArreglo();
System.out.println("Valores antes de ordenar: "); for (int i = 0; i < valores.length; i++) { System.out.print(valores[i] + (i + 1 < valores.length ? ", " : "\n"));
}
ordenamientoBurbuja(valores);
System.out.println("Valores ordenados: "); for (int i = 0; i < valores.length; i++) { System.out.print(valores[i] + (i + 1 < valores.length ? ", " : "\n"));
}
int numeroAleatorio = getRandomNumber(1, 50);
boolean encontrado = false;
for (int valor : valores) { if (valor == numeroAleatorio) { encontrado = true;
break;
}
}
System.out.println("El numero aleatorio " + numeroAleatorio + (encontrado ? " " : " no ") + "fue encontrado"); }
}