Guest User

Untitled

a guest
Aug 10th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. package questaoDesafio;
  2. import java.util.*;
  3.  
  4. public class questaoDesafio {
  5. public static void main (String[] args) {
  6. String nome, teste;// lol;
  7. int tamanho, x, cont, erro, acerto;
  8. boolean logic = true;
  9. //boolean cond = true;
  10. x=0;
  11. Scanner in = new Scanner(System.in);
  12. cont = 6;
  13. erro = 0;
  14. acerto = 0;
  15. //char lol = 'h';
  16. System.out.print("Informe a palavra: ");
  17. nome = in.nextLine();
  18. //char[] arrayTexto = nome.toCharArray();
  19. tamanho = nome.length() - 1;
  20. char[] iguais = new char[nome.length()];
  21. char[] lol = new char[nome.length()];
  22. for (int i = 0; i <= tamanho; i++) {
  23. iguais[i] = '=';
  24. lol[i] = '=';
  25. System.out.print(iguais[i]);
  26. }
  27. do {
  28.  
  29. System.out.print("\n\nDigite uma letra ou palavra: ");
  30. teste = in.nextLine();
  31. char[] arrayteste = teste.toCharArray();
  32. if (teste.length() == 1) {
  33. for (int i = 0; i<= tamanho; i++) {
  34.  
  35. //while (acerto != nome.length() && erro != nome.length()) {
  36. if (nome.charAt(i) == teste.charAt(0)) {
  37. iguais[i] = arrayteste[0];
  38. acerto++;
  39. //System.out.print(iguais[i]);
  40. }
  41. else {
  42. erro++;
  43. //System.out.print(iguais[i]);
  44. }
  45. //}
  46. if (acerto == nome.length()) {
  47. System.out.println("Parabens, vc venceu!");
  48. logic = false;
  49. break;
  50. }
  51. /*else if (erro > nome.length()) {
  52. cont--;
  53. if (cont == 0) {
  54. System.out.println("A palavra não contém essa letra! Perdeu.");
  55. logic = false;
  56. }
  57. else {
  58. System.out.println("A palavra não contém essa letra! "+cont+" tentativas restantes!");
  59. }
  60.  
  61. }*/
  62.  
  63. System.out.print(iguais[i]);
  64.  
  65.  
  66. }
  67. }
  68. else if (teste.length() == nome.length()){
  69. if (nome.equals(teste)) {
  70. System.out.println("Parabens, voce venceu.");
  71. break;
  72. }
  73. else {
  74. cont--;
  75. if (cont == 0) {
  76. System.out.println("A palavra não contém essa letra! Perdeu.");
  77. logic = false;
  78. }
  79. else {
  80. System.out.println("A palavra não contém essa letra! "+cont+" tentativas restantes!");
  81. }
  82. }
  83. }
  84. else {
  85. cont--;
  86. if (cont == 0) {
  87. System.out.println("A palavra não contém essa letra! Perdeu.");
  88. logic = false;
  89. }
  90. else {
  91. System.out.println("A palavra não contém essa letra! "+cont+" tentativas restantes!");
  92. }
  93. }
  94. }while (logic == true);
  95. }
  96. }
Add Comment
Please, Sign In to add comment