0

So I have this executable jar file with a username and password and runs but value doesn't ever continue correctly. Here is an example:

public static void main(String[] args) {
                System.out.println("Hello. I am a program created by Moocow9m. What is your name?");
                InputStream stream = System.in;
                Scanner scanner = new Scanner(stream);
                String input = scanner.next();
                if (input == "armystich"){
                System.out.println("Welcome CODE NAME: ArmyStich!");
                scanner.close();
                }
                else {
                System.out.println("Hello " + input + ". Nice to meet you.");
                scanner.close();
                }
        }
    }

All would work except it would always return to else. Please help.

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
Moocow9m
  • 83
  • 3
  • 10

1 Answers1

0
if (input == "armystich"){

The above checks reference equality. To check for value equality, using the equals method

if ( input.equals("armystich") ){

See How do I compare strings in Java?

Community
  • 1
  • 1
copeg
  • 8,290
  • 19
  • 28
  • That worked but how do i make it not case sensitive? – Moocow9m May 15 '15 at 22:08
  • See the [API for the String](http://docs.oracle.com/javase/7/docs/api/java/lang/String.html) class - there is an `equalsIgnoreCase` method. – copeg May 15 '15 at 22:11