Advertisement
Nasty

Untitled

Sep 23rd, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class Generador {
  5.    
  6.     public static void main(String[] args) {
  7.         char[] op = new char[]{'+', '-'};
  8.         Random rand = new Random();
  9.         Scanner in = new Scanner(System.in);
  10.         int n1, n2, res, input;
  11.         int ac = 0, ne = 0;
  12.         long time = System.currentTimeMillis();
  13.         for(int a = 0; a < 10; a++) {
  14.             n1 = rand.nextInt(30) + 5;
  15.             n2 = rand.nextInt(30) + 5;
  16.             char x = op[rand.nextInt(2)];
  17.             if(x == '+') {
  18.                 // add
  19.                 res = n1 + n2;
  20.                 System.out.print(n1 + " + " + n2 + " = ");
  21.             } else {
  22.                 if(n1 < n2) {
  23.                     int tmp = n1;
  24.                     n1 = n2;
  25.                     n2 = tmp;
  26.                 }
  27.                 // subtract
  28.                 res = n1 - n2;
  29.                 System.out.print(n1 + " - " + n2 + " = ");
  30.             }
  31.             input = in.nextInt();
  32.             if(input == res) {
  33.                 ac++;
  34.                 System.out.println("Correcto");
  35.             } else {
  36.                 ne++;
  37.                 System.out.println("Incorrecto");
  38.             }
  39.         }
  40.         long end = (System.currentTimeMillis() - time) / 1000L;
  41.         System.out.println();
  42.         System.out.println("Has acertado " + ac);
  43.         System.out.println("Has fallado " + ne);
  44.         System.out.println("Tiempo tomado: " + end + "s");
  45.     }
  46.    
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement