Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class Generador {
- public static void main(String[] args) {
- char[] op = new char[]{'+', '-'};
- Random rand = new Random();
- Scanner in = new Scanner(System.in);
- int n1, n2, res, input;
- int ac = 0, ne = 0;
- long time = System.currentTimeMillis();
- for(int a = 0; a < 10; a++) {
- n1 = rand.nextInt(30) + 5;
- n2 = rand.nextInt(30) + 5;
- char x = op[rand.nextInt(2)];
- if(x == '+') {
- // add
- res = n1 + n2;
- System.out.print(n1 + " + " + n2 + " = ");
- } else {
- if(n1 < n2) {
- int tmp = n1;
- n1 = n2;
- n2 = tmp;
- }
- // subtract
- res = n1 - n2;
- System.out.print(n1 + " - " + n2 + " = ");
- }
- input = in.nextInt();
- if(input == res) {
- ac++;
- System.out.println("Correcto");
- } else {
- ne++;
- System.out.println("Incorrecto");
- }
- }
- long end = (System.currentTimeMillis() - time) / 1000L;
- System.out.println();
- System.out.println("Has acertado " + ac);
- System.out.println("Has fallado " + ne);
- System.out.println("Tiempo tomado: " + end + "s");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement