package yossef;
import java.util.Scanner;
public class mini {
private static final int ROCK = 1;
private static final int SCISSORS =2;
private static final int PAPER =3;
private static Scanner input;
public static void main(String[] args) {
input = new Scanner(System.in);
int Scissor=0;
int Rock=0;
int Paper=0;
System.out.println("player1: choose(1)-Rock, (2)-Scissors, or(3)-Paper");
int player1=input.nextInt();
System.out.println("player2: choose(1)-Rock, (2)-Scissors, or(3)-Paper");
int player2=input.nextInt();
if(player1==player2)
{
System.out.println("It's a tie,try again");
}else {
switch(player1) {
case ROCK:
if(player2==Scissor)
System.out.println("player1 wins");
else
System.out.println("player2 wins");
break;
case SCISSORS:
if(player2 ==Paper)
System.out.println("player1 wins");
else
System.out.println("player2 wins");
break;
case PAPER:
if(player2==Rock)
System.out.println("player1 wins");
else
System.out.println("player2 wins");
break;
}
}
}
}
i dont know what to do with this when i play the program an error message shows up as shown in the descreption.
import java.util.Scanner;
public class mini {
private static final int ROCK = 1;
private static final int SCISSORS =2;
private static final int PAPER =3;
private static Scanner input;
public static void main(String[] args) {
input = new Scanner(System.in);
int Scissor=0;
int Rock=0;
int Paper=0;
System.out.println("player1: choose(1)-Rock, (2)-Scissors, or(3)-Paper");
int player1=input.nextInt();
System.out.println("player2: choose(1)-Rock, (2)-Scissors, or(3)-Paper");
int player2=input.nextInt();
if(player1==player2)
{
System.out.println("It's a tie,try again");
}else {
switch(player1) {
case ROCK:
if(player2==Scissor)
System.out.println("player1 wins");
else
System.out.println("player2 wins");
break;
case SCISSORS:
if(player2 ==Paper)
System.out.println("player1 wins");
else
System.out.println("player2 wins");
break;
case PAPER:
if(player2==Rock)
System.out.println("player1 wins");
else
System.out.println("player2 wins");
break;
}
}
}
}
The problem is in if else statement in switch case statement where you are comparing with integer variable with string variable. I hope it is helpful:-)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.