Advertisement
cesarnascimento

Advinhar letra do while else if

May 8th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1.  
  2.  
  3. import java.util.Scanner;
  4. public class teste {
  5.  
  6.  
  7.     public static void main(String[] args) {
  8.        Scanner sc = new Scanner(System.in);
  9.         //boolean errado = true;
  10.         char letra;
  11.         int tentativas = 1;
  12.        
  13.         do {
  14.             System.out.println("Digite a letra: ");
  15.             letra = sc.nextLine().charAt(0);
  16.             if (letra != 'A'){
  17.                 System.out.println("Letra errada.");
  18.                 System.out.println("Tentativas: "+tentativas);
  19.                 ++tentativas;
  20.             }else if (letra == 'A'){
  21.                 System.out.println("Letra correta!!");
  22.             }
  23.         } while(letra != 'A');
  24.        
  25.    
  26.     }  
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement