Advertisement
Tugamars_PT

Untitled

Oct 16th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import java.util.*;
  2. /*
  3. * Exercício 3.12
  4. Altere o jogo AltoBaixo (Exercício 3.4) de forma que quando um jogo acaba, o programa
  5. pergunta “Novo jogo (s/n)?”. O utilizador responde escrevendo uma letra. O programa só
  6. termina se a resposta for “n”.
  7. Pode ler uma palavra com o código:
  8. String resp = sc.next();
  9. e pode testar igualdade com a expressão (resp.equals("n")).
  10. */
  11.  
  12. public class exercicio3l{
  13. public static void main(String [] args){
  14. Scanner sc=new Scanner(System.in);
  15.  
  16.  
  17. int x, tentativas=0;
  18. char alta, baixa, sc, s, n;
  19. boolean resposta=true;
  20. int secret = (int)(100.0*Math.random()) + 1;
  21.  
  22. System.out.printf("introduza numeros até encontar o número secreto !!!! \n");
  23. while(resposta==true){
  24. do{
  25. System.out.printf("introduza um numero: ");
  26. x= sc.nextInt();
  27.  
  28. tentativas++;
  29.  
  30. if(x>secret)
  31. System.out.printf("alto \n");
  32. if(x<secret)
  33. System.out.printf("baixo \n");
  34.  
  35.  
  36. }
  37.  
  38. while(x!=secret);
  39. System.out.printf("Parabéns acertou no número!!!! \n");
  40. System.out.printf("tentou no total"+ tentativas +"vezes");
  41. System.out.printf("deseja repetir? s/n ");
  42. sc= sc.nextChar();
  43. if(sc==s){
  44. resposta=true;
  45. }
  46. if (sc==n){
  47. resposta=false;
  48. }
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement