Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /*
- * Exercício 3.12
- Altere o jogo AltoBaixo (Exercício 3.4) de forma que quando um jogo acaba, o programa
- pergunta “Novo jogo (s/n)?”. O utilizador responde escrevendo uma letra. O programa só
- termina se a resposta for “n”.
- Pode ler uma palavra com o código:
- String resp = sc.next();
- e pode testar igualdade com a expressão (resp.equals("n")).
- */
- public class exercicio3l{
- public static void main(String [] args){
- Scanner sc=new Scanner(System.in);
- int x, tentativas=0;
- char alta, baixa, sc, s, n;
- boolean resposta=true;
- int secret = (int)(100.0*Math.random()) + 1;
- System.out.printf("introduza numeros até encontar o número secreto !!!! \n");
- while(resposta==true){
- do{
- System.out.printf("introduza um numero: ");
- x= sc.nextInt();
- tentativas++;
- if(x>secret)
- System.out.printf("alto \n");
- if(x<secret)
- System.out.printf("baixo \n");
- }
- while(x!=secret);
- System.out.printf("Parabéns acertou no número!!!! \n");
- System.out.printf("tentou no total"+ tentativas +"vezes");
- System.out.printf("deseja repetir? s/n ");
- sc= sc.nextChar();
- if(sc==s){
- resposta=true;
- }
- if (sc==n){
- resposta=false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement