我昨天刚开始使用Java。我尝试过研究,但没有找到任何可以利用的东西。问题是,无论我输入什么作为输入,程序总是输出" Hell"和#34;你好fmdas"。我想我应该将if (BetOrPlay != "Bet");
行写为else if (BetOrPlay != "Bet");
但该计划并不允许我这样做。
import java.util.Scanner;
public class MoneyMaker
{
static Scanner Choice = new Scanner (System.in);
public static void main(String[] args)
{
System.out.println("Do you want to bet your coins or earn more by playing this game?");
try
{
if (Choice.hasNextLine())
{
String BetOrPlay = Choice.nextLine();
if (BetOrPlay == "Bet");
{
System.out.println("Hell");
}
if (BetOrPlay != "Bet");
{
System.out.println("Hello fmdas");
}
}
}
finally
{
Choice.close();
}
}
}
答案 0 :(得分:0)
你实际上并没有在if块下做任何事情。
if (BetOrPlay == "Bet"); //remove ; here
if (BetOrPlay != "Bet"); //remove ; here