0

My Code may look grammatically awful, but that's because I've had to censor out foul language.

I'm trying to get it to terminate when someone enters "bats", "Bats", or "BATS".

import java.util.*;

public class BATS
{

    public static void main(String[] args)
    {

    Scanner BAT = new Scanner(System.in);
    String Bat, BATS;
    System.out.println("What is the most badass flying mammal ever?!");

    Bat = BAT.nextLine();
    Bat = Bat.toUpperCase();

        while(Bat != "BATS")
        {

            System.out.println("No, its BATS!!!!!!!!!! Try again.");
            Bat = BAT.nextLine();
            Bat = Bat.toUpperCase();
            if(Bat == "BATS")
            {
            System.out.println("YOU'RE  RIGHT THEY ARE !!!!!");
            break;  
            }
        }
    }
}
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Nick
  • 1

1 Answers1

0

while(Bat != "BATS") is wrongly

you need to compare content and not references...


Do instead:

while(!"BATS".equalsIgnoreCase(Bat))
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97