Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Apertadinho {
- public static void jogarApertadinho() {
- int min = 0;
- int max = 100;
- int numeroSorteado;
- numeroSorteado = (int) Math.round(Math.random() * 99+1);
- System.out.println(numeroSorteado);
- int tentativas = 0;
- int chute = 0;
- Scanner entrada = new Scanner(System.in);
- while (chute!=numeroSorteado)
- {
- tentativas++;
- System.out.println("Digite um valor entre zero e cem!");
- chute = entrada.nextInt();
- if (tentativas == 1){
- if (chute<0 || chute>100)
- {
- System.out.println("Digite apenas numeros entre 1 e 100.");
- }
- }
- else if (chute <= min || chute > max)
- {
- break;
- }
- else
- {
- if (chute>numeroSorteado)
- {
- System.out.println("O numero sorteado está entre 1 e "+chute);
- max = chute;
- }
- if (chute<numeroSorteado)
- {
- System.out.println("O numero sorteado está entre " +chute+ " e " +100);
- min = chute;
- }
- }
- }
- if (chute == numeroSorteado)
- {
- System.out.println("Você acertou o numero!");
- System.out.println("Numero de tentativas: " + tentativas);
- }
- else
- {
- System.out.println("VOCÊ PERDEU, lixo!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment