简体   繁体   English

嗨,我是 Java 的新手,我在试图找出底部“case SCISSORS:”的问题时遇到了麻烦,有人可以帮我:)

[英]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.

相关问题 我在 Java 中遇到了很多随机数问题,想知道是否有人可以提供帮助? 我对编码很陌生 - Im having a lot of trouble with randoms in Java and was wondering if someone could help? I am quite new to coding 嗨,我在安装面板JScrollPane内部的表时遇到麻烦 - Hi Im having trouble fitting the Table that is inside a JScrollPane in a Panel 嗨,我是新手,我是否制作了一个允许我循环提问的 Java 程序? - Hi, Im new, do I make a java program that allows me to loop a question? 我无法在我的 JFrame 中显示图形 - Im having trouble trying to display graphics in my JFrame 我试图为我的课程制作一个税收计算器,但我陷入困境,有人可以帮忙,因为我不知道(Java) - Im trying to make a tax calculator for my coursework but im stuck hoplefull someone can help because ive got no clue (Java) 编译Java程序时遇到问题,我是新手。 无法弄清楚如何处理目录 - Having trouble compiling a Java program, I am new to it. Can't figure out what to do with directories 我生疏了,无法弄清楚如何在Java swing中进行异常处理 - Im rusty, can't figure out how to do exception handling right in Java swing 我试图运行BFS算法,它让我失望 - Im trying to run BFS Algo and it throws me out Java多线程阅读..请帮助IM对Java非常新:( - java multithread reading..please help im very new to java:( Eclipse 不断给出错误消息。 有人可以帮忙吗? 顺便说一句,我是 Java 新手 - Eclipse keeps giving error message. can someone help? im new in java btw
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM