Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package questaoDesafio;
- import java.util.*;
- public class questaoDesafio {
- public static void main (String[] args) {
- String nome, teste;// lol;
- int tamanho, x, cont, erro, acerto;
- boolean logic = true;
- //boolean cond = true;
- x=0;
- Scanner in = new Scanner(System.in);
- cont = 6;
- erro = 0;
- acerto = 0;
- //char lol = 'h';
- System.out.print("Informe a palavra: ");
- nome = in.nextLine();
- //char[] arrayTexto = nome.toCharArray();
- tamanho = nome.length() - 1;
- char[] iguais = new char[nome.length()];
- char[] lol = new char[nome.length()];
- for (int i = 0; i <= tamanho; i++) {
- iguais[i] = '=';
- lol[i] = '=';
- System.out.print(iguais[i]);
- }
- do {
- System.out.print("\n\nDigite uma letra ou palavra: ");
- teste = in.nextLine();
- char[] arrayteste = teste.toCharArray();
- if (teste.length() == 1) {
- for (int i = 0; i<= tamanho; i++) {
- //while (acerto != nome.length() && erro != nome.length()) {
- if (nome.charAt(i) == teste.charAt(0)) {
- iguais[i] = arrayteste[0];
- acerto++;
- //System.out.print(iguais[i]);
- }
- else {
- erro++;
- //System.out.print(iguais[i]);
- }
- //}
- if (acerto == nome.length()) {
- System.out.println("Parabens, vc venceu!");
- logic = false;
- break;
- }
- /*else if (erro > nome.length()) {
- cont--;
- if (cont == 0) {
- System.out.println("A palavra não contém essa letra! Perdeu.");
- logic = false;
- }
- else {
- System.out.println("A palavra não contém essa letra! "+cont+" tentativas restantes!");
- }
- }*/
- System.out.print(iguais[i]);
- }
- }
- else if (teste.length() == nome.length()){
- if (nome.equals(teste)) {
- System.out.println("Parabens, voce venceu.");
- break;
- }
- else {
- cont--;
- if (cont == 0) {
- System.out.println("A palavra não contém essa letra! Perdeu.");
- logic = false;
- }
- else {
- System.out.println("A palavra não contém essa letra! "+cont+" tentativas restantes!");
- }
- }
- }
- else {
- cont--;
- if (cont == 0) {
- System.out.println("A palavra não contém essa letra! Perdeu.");
- logic = false;
- }
- else {
- System.out.println("A palavra não contém essa letra! "+cont+" tentativas restantes!");
- }
- }
- }while (logic == true);
- }
- }
Add Comment
Please, Sign In to add comment