[英]Hi, im new to Java and im having trouble trying to figure out the problem with “case SCISSORS:” at the bottom can somebody help me:)
package yossef; package 优素福;
import java.util.Scanner;导入 java.util.Scanner;
public class mini {公共 class 迷你 {
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.问题出在 switch case 语句中的 if else 语句中,您在其中将 integer 变量与字符串变量进行比较。 I hope it is helpful:-)
我希望它会有所帮助:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.