我的小文字游戏出错了,不知道为什么

时间:2015-08-29 01:49:00

标签: java

这是我的计算机科学课程的介绍(代码的第一部分格式很奇怪,无法弄清楚如何在这个网站上格式化),它正在得到这两个错误。 (再次抱歉格式化,尽我所能)

C:\ Users \ Zach \ Desktop \ shitty java programs \ Spookster.java:23:error:' else'没有'如果'             } else if(actionTwo == 2); {               ^ C:\ Users \ Zach \ Desktop \ shitty java programs \ Spookster.java:39:error:' else'没有'如果'             } else if(actionThree == 2); {               ^ 2个错误

import java.util.*;

public class Spookster
{
public static void main(String[] args)
{
    Scanner keyboard = new Scanner(System.in);
    int actionOne, actionTwo, actionThree;

    System.out.println("You wake up in a metallic room. There is a knife next to you, and there is a door ahead of you.");
    System.out.print("Press 1 to go to the door, press 2 to pick up the knife: ");
    actionOne = keyboard.nextInt();

    if (actionOne == 1) {
        System.out.println("You walk to the door. There is a small window that you could look through.");
        System.out.println("You could also just open the door right there.");
        System.out.print("Press 1 to look through the window, press 2 to go through the door: ");
        actionTwo = keyboard.nextInt();
        if (actionTwo == 1); {
            System.out.println("You look through the window and see a tall creature inside a cockpit.");
            System.out.println("Suddenly you are grabbed from behind and everything is black");
            System.out.println("YOU ARE DEAD");
        } else if (actionTwo == 2); {
            System.out.println("You open the door and hear something behind you, you shut it fast then are in shock");
            System.out.println("Another creature is staring you down in front of you. He runs at you with a electrical sword");
            System.out.println("Enter 1 to dodge, enter 2 to defend yourself");
        }

    } else if (actionOne == 2) {
        System.out.println("You pick up the knife and hear something behind you.");
        System.out.println("You blindly throw your hand backwards and realise you killed a tall creature.");
        System.out.println("There is an advanced gun in his hand");
        System.out.print("Press 1 to pick up the gun, press 2 to leave it be: ");
        actionThree = keyboard.nextInt();

        if (actionThree == 1); {
            System.out.println("You grab the gun and the creature moves, you quickly aim and fire");

        } else if (actionThree == 2); {
            System.out.println("The creature becomes conscious and aims the gun at you, you stand in fear.");
            System.out.println("Suddenly you hear a loud noise and everything is black.");
            System.out.println("YOU ARE DEAD");
        }
    }
}

}

2 个答案:

答案 0 :(得分:0)

您在此处终止if正文(和else if正文)

if (actionTwo == 1); {
    System.out.println("You look through the window and see a tall creature inside a cockpit.");
    System.out.println("Suddenly you are grabbed from behind and everything is black");
    System.out.println("YOU ARE DEAD");
} else if (actionTwo == 2); {
    System.out.println("You open the door and hear something behind you, you shut it fast then are in shock");
    System.out.println("Another creature is staring you down in front of you. He runs at you with a electrical sword");
    System.out.println("Enter 1 to dodge, enter 2 to defend yourself");
}
用分号表示。删除那些

if (actionTwo == 1) {
    System.out.println("You look through the window and see a tall creature inside a cockpit.");
    System.out.println("Suddenly you are grabbed from behind and everything is black");
    System.out.println("YOU ARE DEAD");
} else if (actionTwo == 2) {
    System.out.println("You open the door and hear something behind you, you shut it fast then are in shock");
    System.out.println("Another creature is staring you down in front of you. He runs at you with a electrical sword");
    System.out.println("Enter 1 to dodge, enter 2 to defend yourself");
}

答案 1 :(得分:0)

在if和else if语句之后删除semilcolons。