Hello, World! Fiz o desafio, mas quis "apimentar" mais as coisas e fiz uma versão mais completa do jogo do número secreto //eu sei que o desafio era para deixar o número aleatório entre 0 e 100, mas acabei colocando só até 10
import java.util.Random;
import java.util.Scanner;
public class DesafioNumeroSecreto {
public static void main(String[] args) {
Scanner leitura = new Scanner(System.in);
int numeroAleatorio = new Random().nextInt(10);
int tentativas = 5;
int chute;
int ficha = 1;
String joguinho;
joguinho = """
Bem vindo ao jogo de Acerte o Número!
coloque sua ficha digitando quantas rodadas você quer
R$0,50 R$1,00 R$1,25
1 RODADA 2 RODADAS 3 RODADAS
""";
System.out.println(joguinho);
ficha = leitura.nextInt();
while (ficha >= 1){
if (ficha > 3){
System.out.println("O MÁXIMO DE FICHAS É 3.");
break;
}
System.out.println(String.format("Adivinhe o número de 1 à 10 com %d tentativas",tentativas));
chute = leitura.nextInt();
tentativas--;
if (chute == numeroAleatorio) {
String ganhou = """
PARABÉNS! ! !
VOCÊ ADIVINHOU O NUMÉRO SECRETO""";
System.out.println(ganhou);
tentativas = 3;
break;
}
if(chute < numeroAleatorio){
System.out.println("O número é maior que " + chute);
}
if (chute > numeroAleatorio){
System.out.println("O número é menor que " + chute);
}
if (tentativas == 0){
String perdeu;
perdeu = """
Acabaram as suas tentativas...
Fichas disponíveis: %d
""";
ficha--;
System.out.println(String.format(perdeu,ficha));
numeroAleatorio = new Random().nextInt(10);
tentativas = 5;
}
if (ficha == 0){
break;
}
}
}
}
a sintaxe ficou meio bagunçada... aceito opiniões e métodos mais eficazes :^)