I am new to java programming and just getting into the if-else statements. This program must be made with basic Java principles using if-else statements only. I am trying to compute the winner of the program but I can only manage to input one if else statement and one if statement. When I input the second if else statement for the next computation, I receive an error message saying
I have tried to just use an if statement or an else statement. I have also tried to change the indention and bracket locations.
// User Choices
System.out.println("Please choose 1 for scissors 2 for lizard or 3 for spock, enter anything else to automatically lose: ");
int user = input.nextInt();
if ((int)user == 1) {
System.out.println("You have chose Scissors "); }
if ((int)user == 2) {
System.out.println("You have chose Lizard "); }
if ((int)user == 3) {
System.out.println("You have chose Spock "); }
// Computer Choices
int computer = rnd.nextInt(3);
if ((int)computer == 1) {
System.out.println("The computer chose Scissors "); }
if ((int)computer == 2) {
System.out.println("The computer chose Lizard "); }
if ((int)computer == 3) {
System.out.println("The computer chose Spock "); }
//Calculate the winner of the variables
if (user == computer) {
System.out.println("It's a tie!");
}else if (user == 1 && computer == 2 ); {
System.out.println("You Have Won!");
}else if (user == 2 && computer == 3) {
System.out.println("You have Won!");
}
I expect this program to compute the winner of the 3 variables and to determine if it is a tie. It also must output the users automatic loss when anything else is input.
Aucun commentaire:
Enregistrer un commentaire