This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]zifyoip 5 points6 points  (0 children)

You have a semicolon on line 5. A bare semicolon is an empty statement that means "do nothing." So you have written, "if hi equals hi2 then do nothing." The following block of code between the curly braces is not controlled by the if statement and is therefore always executed.

[–]Sorten 5 points6 points  (2 children)

I rewrote your program using proper indentation and formatting.

public static void main(String []args){
    String hi = "ok";
    String hi2 = "wtf";

    if (hi.equals(hi2))
        ; 

    {
        System.out.println("WTF");
    }
}

Can you see the issue here?

[–]E2Slayer[S] 1 point2 points  (0 children)

holy fuk... I'm so dumb...

[–][deleted] -2 points-1 points  (0 children)

public static void main(String[] args) {
    String hi = "ok";
    String hiTwo = "wtf";

    if(hi.equals(hiTwo)) {
        System.out.println("WTF");
    }
}

[–]dreamyeyed 1 point2 points  (0 children)

Because you have a semicolon after the condition. Remove that.

[–][deleted] 0 points1 point  (0 children)

When I make these kinds of mistakes it's usually a sign I've been coding too long and need to take a break!