-1

I just started using Java yesterday. I've tried researching but didn't find anything I could make use of. The problem is that no matter what I type as an Input the program always outputs "Hell" and "Hello fmdas". I think I should write the if (BetOrPlay != "Bet"); Line as else if (BetOrPlay != "Bet"); But the program doesn't allow me to do that.

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();
        }   
    }
}
mpromonet
  • 11,326
  • 43
  • 62
  • 91
  • 1
    Use .equals() to compare Strings as the marked duplicate shows. Also, putting semicolon (;) after if statement, makes the if statement useless. – user3284549 Jan 09 '16 at 13:59

1 Answers1

0

You don't actually do anything under the if blocks.

  if (BetOrPlay == "Bet"); //remove ; here
  if (BetOrPlay != "Bet"); //remove ; here