微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

获取用户输入以在 if 语句中使用以在故事中做出选择的问题

如何解决获取用户输入以在 if 语句中使用以在故事中做出选择的问题

我需要用 Java 编写一个代码来完成一个多选故事,但是我无法让我的代码读取用户输入并让它继续这个故事。 她是我到目前为止编写的代码。 (我认为代码中的行距是正确的,如果不是很抱歉,我把代码在这里时可能会搞砸)

import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(system.in);
      
    System.out.println("Wlelcome to survive The desert. Made by Thomas Reinhardt");
// The first choice for the user 
    System.out.println("You find your self stranded in the desert. you need to find food and water quickly. Right Now you have two opptions:");
    System.out.println("(A): Travle to what looks like an oasis in the didstance:");
    System.out.println("(B): keep exploring to find something else");
    String choice = sc.nextLine();
// evaluating the useres first choice 
// if the user passes the first choice 
    if (choice == "A")
        {
        System.out.println("You find water and are able to survive the night");
        System.out.println("");
        // making the second choice 
        System.out.println("Its Now the next day. you find your self felling hungry you need food.");
         System.out.println("(C) stay at the oasis and wait for a food sorce to come");
         System.out.println("(D) Go out and serch for some food");
        String choiceTwo = sc.nextLine();

        // evaluating the second input
        // if the user fails the second choice
        if (choiceTwo == "C")
        {
            System.out.println("You wait at the oasis for days no food source arives you evetualuly  starve to death");
        }
        //if the user passes the second choice
        if (choiceTwo == "D")
        {
            System.out.println("You find a fresh kill and was able to salvage some meat. you Now have food. ");
            // setting up the third choice
            System.out.println("Now that you are back at the oasis you need to find a way to get saved");
            System.out.println("(E) you can stay at the oasis and create a SOS signal at it: ");
            System.out.println("(F) Trava; twords what looks like a small town in the distance");
            String choiceThree = sc.nextLine();
            //evaluates the third choice
            // if the user passes the third choice
            if (choiceThree == "E" )
            {
                System.out.println("You built the SOS signal and help has finaly arived and you were saved");
            }
            // if the user fails the third choice
            if (choiceThree == "F")
            {
                System.out.println("You walk twords what you thought was a town but it just keeps getting farther away. The town was a halusination you end up wandering forever and evetualy die");
            }
        }
        }
    // the user fails the first choice
    if (choice == "B")
      {
        System.out.println("You wander for hours and find nothing you die of sarvation");

      }


  }
} 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?