Guest User

Untitled

a guest
Jul 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. public static void main(String[] args) throws IOException {
  2. BufferedReader entrada=new BufferedReader(new InputStreamReader(System.in));
  3. int j;
  4. int i;
  5. int juego[] = new int [6];
  6. int resultado[] = new int [6];
  7. //try
  8.  
  9. Random rand = new Random(); //Nos genera los número aleatorios
  10. String[] introducidos = new String[50];
  11. for (i=0;i<=5;i++) {
  12. int correcto = 2;
  13. int num_final = 0;
  14. System.out.println("Introduzca el número " +i );
  15. while(correcto==2){
  16. correcto = 1;
  17.  
  18. try{
  19. num_final = Integer.parseInt(entrada.readLine());
  20. } catch(Exception e){
  21.  
  22. System.out.println("No es un número. Vuelve a introducirlo...");
  23. correcto=2;
  24.  
  25. }
  26.  
  27.  
  28.  
  29. try{
  30.  
  31. int[] posibles = new int[50];
  32.  
  33. int search = posibles[num_final];
  34.  
  35.  
  36. }
  37.  
  38. catch( Exception u ) {
  39. System.out.println("No está entre el 0 y el 49. Vuelve a introducirlo...");
  40. correcto = 2;
  41. }
  42. try{
  43. String imp = introducidos[num_final];
  44. int trier = Integer.parseInt(imp);
  45. System.out.println("Ese número ha sido repetido. Vuelve a introducirlo...");
  46. correcto=2;
  47.  
  48. }catch(Exception e){
  49.  
  50. }
  51.  
  52.  
  53. if(correcto==1){
  54.  
  55. juego[i]=num_final;
  56. introducidos[num_final]="1";
  57. }
  58.  
  59.  
  60. }
  61.  
  62.  
  63.  
  64.  
  65. }
  66. //Bucle que nos genera los números aleatorios.
  67.  
  68. for (i=0;i<=5;i++) {
  69. while(true){
  70. int random = rand.nextInt(48)+1;
  71. //Buscamos que el número no esté repetido:
  72. int repetido=0;
  73. for(int a=0;a<=i;a++){
  74.  
  75. if(resultado[a]==random){
  76. repetido=1;
  77.  
  78. }
  79.  
  80. }
  81. if(repetido==0){
  82. resultado[i]=random;
  83.  
  84. System.out.println(resultado[i]);
  85. break;
  86. }
  87.  
  88.  
  89. }
  90. }
  91.  
  92.  
  93.  
  94. //Pedimos los números
  95.  
  96. //Comprobamos los aciertos.
  97. int actual=0;
  98. int aciertos=0;
  99. for(int s=0;s<juego.length;s++){
  100. actual=juego[s];
  101. //Comprobamos si existe dentro de los numeros generados antes:
  102. for(int p=0;p<resultado.length;p++){
  103.  
  104. if(resultado[p]==actual){
  105. aciertos++;
  106. }
  107. }
  108. }
  109. System.out.println("Aciertos totales: "+ aciertos);
  110. }
Add Comment
Please, Sign In to add comment