Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package clase3;
- import java.util.*;
- // nroAleatorio = (int) (Math.random() * 100) + 1;
- public class ProximoPrimo {
- public static void main(String[] args)
- {
- boolean gano=false;
- int nroAleatorio, nroJugador;
- Scanner scan = new Scanner(System.in);
- Random generador = new Random();
- nroAleatorio = 1 + generador.nextInt(100);
- System.out.println("nro Aleatorio: "+ nroAleatorio);
- while(!gano)
- {
- System.out.println("Ingrese el nro primo que le sigue: ");
- nroJugador = scan.nextInt();
- if(proximoPrimo(nroAleatorio)==nroJugador)
- {
- System.out.println("Acerto");
- gano = true;
- }
- else
- System.out.println("Fallaste");
- }
- }
- static boolean esPrimo(int nro)
- {
- int cont = 0;
- for(int x=1; x<=nro; x++)
- {
- if(nro%x == 0)
- cont += 1;
- }
- if(cont == 2)
- {
- return true;
- }
- else
- return false;
- }
- static int proximoPrimo(int aleatorio)
- {
- int i = aleatorio + 1 ;
- while(!esPrimo(i))
- {
- i++;
- }
- return i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement