选择自己的冒险。输入“朋友”时无法输出消息

时间:2019-02-19 19:39:47

标签: java eclipse

public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.out.println("Choose your own adventure");
        System.out.println("For the past 3 months you have not been spending your money wisley");
        System.out.println("Due to your choices you have not been able to pay your bills");
        System.out.println("You are in a horrible postion and you are about to lose everything you own. The only way for you to survive is by making the right choices");
        System.out.println("What would you like to do? Make sure you think about your decsions more than once");
        System.out.println("Enter in one, two or three to start");

        Scanner scan1 = new Scanner(System.in);
        String optionone = scan1.nextLine();

        if (optionone.equals("one")) {
            System.out.println("its 2 am and you're stressed because you haven't paied your rent for the last two months. You're being kicked out in the next week if you don't pay the owner the money.");
            System.out.println("Enter in call, no rent, or drink to continue");
            optionone = scan1.nextLine();
            if (optionone.equals("call")) {
                System.out.println("You're desprate for money and while you're thinking of how to pay your rent your friend calls you who has just left from jail. He tells you to come to the place he is living at");
            }else if (optionone.equals("no rent")) {
                System.out.println("You choose not to pay your rent and you get kicked out of your apartment");
                System.out.println("Enter in friend to go to your friend's house or friend's house to go to his house");
            } else if (optionone.equals("friend")) {
                    System.out.println("You ask your friends if you can stay at their place, but you owe all of them hundreds of dollars. The only way to live with them is to pay them back which you cannot so now you're living in the streets. You have nothing to keep ypu warm and in 2 days you frezze to death");
                }else if (optionone.equals("drink")) {
                System.out.println("You choose to drink alcholo until you're so drunk you're knocked out. Unfortunatley, you also drank so many redbulls you ended up dying");
                System.out.println("Game ended");
            }
        }


// other story
        else if (optionone.equals("two")) { 
            System.out.println("You're staying up late to finish some work you have to finish and all of a sudden you get a call on your homephone and cellphone from an unknown caller ");


// other story
        }else  { ;
            System.out.println("Your are watching TV at 4 am instead of going to sleep at work and all of a sudden your lights go out");
        }
        String option2 = scan1.nextLine();
    }
}

1 个答案:

答案 0 :(得分:0)

确定输入正确吗?

如果过程如下:

“一个”然后是“朋友”,那么您应该会收到消息

  

您问朋友是否可以留在他们的地方...

它对我有用,因此请确保您输入的不是“朋友”或“朋友”之类的内容。您正在专门检查“朋友”,而不是其他任何东西。

保重,祝你好运。

编辑:为澄清起见,问题在于if语句。您实际上是在询问用户是否键入“一个”,然后他们是否键入 “通话”,“免租”,“饮料”或“朋友”。它不会检查用户是否键入“不出租”,然后键入“朋友”。