Guest User

Untitled

a guest
May 31st, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Apertadinho {
  4.  
  5.    
  6.     public static void jogarApertadinho() {
  7.         int min = 0;
  8.         int max = 100;
  9.         int numeroSorteado;
  10.         numeroSorteado = (int) Math.round(Math.random() * 99+1);
  11.         System.out.println(numeroSorteado);
  12.    
  13.     int tentativas = 0;
  14.     int chute = 0;
  15.    
  16.     Scanner entrada = new Scanner(System.in);
  17.  
  18.    
  19.     while (chute!=numeroSorteado)          
  20.       {
  21.         tentativas++;    
  22.         System.out.println("Digite um valor entre zero e cem!");
  23.         chute = entrada.nextInt();
  24.         if (tentativas == 1){
  25.         if (chute<0 || chute>100)
  26.            {   
  27.                 System.out.println("Digite apenas numeros entre 1 e 100.");
  28.            }
  29.         }
  30.         else  if (chute <= min || chute > max)
  31.             {
  32.                 break;
  33.             }
  34.        
  35.       else
  36.         {
  37.             if (chute>numeroSorteado)      
  38.                    {   
  39.                         System.out.println("O numero sorteado está entre 1 e "+chute);
  40.                         max = chute;
  41.                    }
  42.                 if (chute<numeroSorteado)      
  43.                    {
  44.                         System.out.println("O numero sorteado está entre " +chute+  " e " +100);
  45.                         min = chute;
  46.                    }
  47.             }
  48.       }
  49.      
  50.     if (chute == numeroSorteado)
  51.     {
  52.          System.out.println("Você acertou o numero!");
  53.          System.out.println("Numero de tentativas: " + tentativas);
  54.     }
  55.     else
  56.     {
  57.         System.out.println("VOCÊ PERDEU, lixo!");
  58.     }
  59.      
  60.  
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment