1
resposta

MINHA SOLUÇÃO - Jogo Adivinhação

import java.util.Scanner;
import java.util.Random;

public class GeradorDeNumeros {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int numeroCorreto = new Random().nextInt(100);
        int chuteDoPlayer = 0;

        //System.out.println("Debug: "+numeroCorreto);

        for (int i = 4; i >= 0; i--) {
            int tentativas = i;
            System.out.println("Qual é o seu chute?: ");
            chuteDoPlayer = scan.nextInt();
            
            if (chuteDoPlayer > numeroCorreto) {
                System.out.println("\nO numero correto é MENOR");
                System.out.printf("Você tem mais %d tentativas...", tentativas);
            } else if (chuteDoPlayer < numeroCorreto) {
                System.out.println("\nO numero correto é MAIOR");
                System.out.printf("Você tem mais %d tentativas...", tentativas);
            } else {
                System.out.printf("\nVocê acertou, o numero era %d", numeroCorreto);
                return;
            }
        }

        System.out.println("\n\nAparentemente você falhou. Tente novamente.");
        System.out.printf("\nO numero correto era %d. FOI QUASE!!", numeroCorreto);
    }
}
1 resposta

Olá Iago!

Seu código para o jogo de adivinhação está muito bem estruturado e cumpre bem o objetivo da atividade. Mandou super bem!

Continue praticando e explorando cada vez mais!

Espero ter ajudado! Bons estudos!

Sucesso

Um grande abraço e até mais!

Caso este post tenha lhe ajudado, por favor, marcar como solucionado ✓. Bons Estudos!