Advertisement
Chanchoveloz

adivina la letra

Aug 15th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. // programa de adivina letra que se entra por teclado para practicar el do...while
  2. //
  3.  
  4. class adivinaletra {
  5.  
  6. public static void main(String[] args)
  7. // TODO Auto-generated method stub
  8. throws java.io.IOException {
  9. char ch, resp = 'K';
  10. do{
  11. System.out.println("Elija una letra entre A y Z");
  12. System.out.println("Puede adivinar? ");
  13.  
  14. // lea una letra pero salte cr/lf
  15.  
  16. // Esto es porque el control de carro y el line feed alteran el valor del char
  17.  
  18. //
  19.  
  20.  
  21. do{
  22. ch=(char) System.in.read(); // lee un caracter desde el teclado
  23. }
  24. while (ch=='\n'| ch== '\r');
  25. System.out.println("");
  26. System.out.println("");
  27. System.out.println("char= "+ch);
  28. System.out.println("");
  29.  
  30. if (ch== resp) System.out.println("***Acertó***");
  31. else{
  32. System.out.println();
  33. System.out.println();
  34. System.out.println("Disculpe, eligió ");}
  35. if (ch<resp) System.out.println("muy bajo");
  36. else{
  37. System.out.println();
  38. System.out.println();
  39. System.out.println("muy alto");
  40. System.out.println("Pruebe nuevamente\n");
  41.  
  42. }
  43. }
  44. while (resp !=ch);
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement