问题描述
我需要用 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 (将#修改为@)