1
"A very common joke among 3 friends is the game of 2 or 1. In this game, the winner is different from the other two and, if the three choose equal values, the game ends tied. So consider three friends A, B and C, who are playing 2 or 1: your show should show which one is the winner or if there was a tie. For this, read an N number that indicates the total number of matches they will play, and then read the values A, B and C (integers) of each friend. Consider that these values will always be 2 or 1. Show on the screen who was the winner or if there was a draw. The program will end when N is zero.
My code:
public static void main(String[] args) {
Scanner ler = new Scanner(System.in);
Random rand = new Random();
int numero1 = rand.nextInt(2) + 1;
int numero2 = rand.nextInt(2) + 1;
int numero3 = rand.nextInt(2) + 1;
int N;
System.out.println("DOIS OU UM!");
System.out.print("Quantas partidas serão jogadas? ");
do {
N = ler.nextInt();
System.out.println("Jogador 1: "+numero1);
System.out.println("Jogador 2: "+numero2);
System.out.println("Jogador 3: "+numero3);
System.out.println("------------");
if (numero1 != numero2 && numero1 != numero3)
System.out.println("Jogador 1 venceu!");
else if (numero2 != numero1 && numero2 != numero3)
System.out.println("Jogador 2 venceu!");
else if (numero3 != numero1 && numero3 != numero2)
System.out.println("Jogador 3 venceu!");
else
System.out.println("O jogo terminou empatado!");
break;
} while (N > 0);
System.out.println("Fim de Jogo!");
}
The code until it’s validating who the winner is and it’s a draw. The problem is the amount I report, and it shows only once, and when I enter 0 it does not go straight to "Game Over!".
Thank you very much friend! I was even breaking my head with the do...while and it was the detail of the decrease. I also appreciate the explanation of the break within the loop. Good evening!
– Mario Puebla Junior