Java中不是Statement错误。 (创建String以及其他行时)

时间:2021-09-05 22:45:49
Scanner reader = new Scanner(System.in);
    String continue;
    do {
        if (eHealth > 0 && pHealth > 0) {
            if (ranAway != true && stuck = true){
                stuck = false;
                System.out.println("You are now stuck with the monster forever. Good job.\n"
                + "Would you like to fight again?\n");
                continue = reader.nextLine();
                if ("Yes".equals(continue) || "yes".equals(continue)){
                    pHealth = 1500;
                    assignHealth();
                    Fight();
                }else if ("No".equals(continue) || "no".equals(continue)) {
                    System.exit(0);
                }
            }else if (ranAway = true && stuck != true) {
                ranAway = false;
                System.out.println("You ran away from your problems like the coward you are.\n"
                                    + "Do you want to fight again\n");
                continue = reader.nextLine();
                if ("Yes".equals(continue) || "yes".equals(continue)){
                    pHealth = 1500;
                    assignHealth();
                    Fight();
                }else if ("No".equals(continue) || "no".equals(continue)) {
                    System.exit(0);
                }
            }else {
                Fight();
            }
        }else if (eHealth > 0 && pHealth <= 0){
            System.out.println("Oh noes. You got de_stroyed by the monster! What a shame.\n"
                                + "Would you like to fight again?\n");
            continue = reader.nextLine();
            if ("Yes".equals(continue) || "yes".equals(continue)){
                    pHealth = 1500;
                    assignHealth();
                    Fight();
                }else if ("No".equals(continue) || "no".equals(continue)) {
                    System.exit(0);
                }
        }else if (eHealth <= 0 && pHealth > 0){
            System.out.println("Congrats! You killed the troll!\n"
                                + "Would you like to play again?\n");
            continue = reader.nextLine();
            if ("Yes".equals(continue) || "yes".equals(continue)){
                    pHealth = 1500;
                    assignHealth();
                    Fight();
                }else if ("No".equals(continue) || "no".equals(continue)) {
                    System.exit(0);
                }
        }
    }

This is the section throwing errors. The context is just a small fight against a troll. The option to restart is given. Some items will activate the booleans you end up seeing. The main lines that seem to be giving errors are the IF statements as well as the String continue;. How can I solve this?

这是抛出错误的部分。上下文只是与巨魔的一场小小的斗争。给出了重启的选项。有些项目会激活您最终看到的布尔值。似乎给出错误的主线是IF语句以及String continue;。我怎么解决这个问题?

1 个解决方案

#1


1  

if (ranAway = true && stuck != true)

This condition is wrong ( "ranAway = true" is actually an assignment), and for this section you can simply state:

这种情况是错误的(“ranAway = true”实际上是一个赋值),对于本节,您可以简单地说明:

if (ranAway && !stuck)

as you probably know, you should have used "==" for the condition if it was necessary. I'm not sure if this fixes your issue because there's a lot of code missing, but it might be the problem with your program.

你可能知道,如果有必要,你应该使用“==”作为条件。我不确定这是否解决了您的问题,因为缺少很多代码,但可能是您的程序存在问题。

#1


1  

if (ranAway = true && stuck != true)

This condition is wrong ( "ranAway = true" is actually an assignment), and for this section you can simply state:

这种情况是错误的(“ranAway = true”实际上是一个赋值),对于本节,您可以简单地说明:

if (ranAway && !stuck)

as you probably know, you should have used "==" for the condition if it was necessary. I'm not sure if this fixes your issue because there's a lot of code missing, but it might be the problem with your program.

你可能知道,如果有必要,你应该使用“==”作为条件。我不确定这是否解决了您的问题,因为缺少很多代码,但可能是您的程序存在问题。