• Lenguaje

    Java usando Scanner

  • Descripción

    Genere número aleatorio de 1 a 38 si es loto normal y de 1 a 10 si es loto mas. Debe hacer un menú para seleccionar loto normal o loto mas.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.Scanner;

public class LotoNormalYLotoMas {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int loto, numero_aleatorio, rand;
        System.out.print("Ingresa el valor de rand: ");
        rand = in.nextInt();
        in.nextLine();
        System.out.println("Selecciona el valor de loto.");
        System.out.println("\t1.- loto normal");
        System.out.println("\t2.- loto mas");
        System.out.print("\t: ");
        do {
            loto = in.nextInt();
            in.nextLine();
            if (loto<1||loto>2)
                System.out.print("Valor incorrecto. Ingr\u00E9salo nuevamente.: ");
        } while (loto<1||loto>2);
        if(loto==1)
            numero_aleatorio=1+rand()%38;
        else
            numero_aleatorio=1+rand()%10;
        System.out.println("Valor de numero aleatorio: " + numero_aleatorio);
    }

}