0

I'm writing a simple code to test the value that was inputted to my constant value.

I declared this code as my constant value.

String LetMeThrough = "drunk";
String GotAnID = "drunk";

This is the whole code.

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
    Scanner DrunkTest = new Scanner(System.in);

    String InputDrunk;
    String InputDrunkAgain;

    String LetMeThrough = "drunk";
    String GotAnID = "drunk";



    System.out.print("Type drunk: ");
    InputDrunk= DrunkTest.next();
    System.out.print("Re Type drunk: ");
    InputDrunkAgain = DrunkTest.next();

    if(InputDrunk == LetMeThrough & InputDrunkAgain == GotAnID){
        System.out.print("You're not DRUNK");
    }
    else
        System.out.print("You're F***** DRUNK");

}}

The problem is that if I type "drunk" on both. I will get "You're F****** DRUNK" instead of the "You're not DRUNK". When the inputted values is the same as my constant values.

Z'K
  • 29
  • 9
  • 4
    so many times already answered this question... – drgPP Mar 24 '15 at 11:19
  • Sorry, I didn't know it. – Z'K Mar 24 '15 at 11:20
  • `String.equals()` made me loathe Java as soon as I ran into it the first time. – Bmo Mar 24 '15 at 11:26
  • Don't change question's title with (SOLVED), to mark question as accepted check this link: http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work , you must use the arrows and the check to rate and validate the answers you receive. – Jordi Castilla Mar 24 '15 at 11:26

1 Answers1

5

You must use String::equals method to compare.

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109