Johnny Appleline
Johnny Appleline

Reputation: 1

dual if statements

Really basic question here involving if statements.

If a=b and c=d
    System.out.println ("True");

How would I write those if statements in Java code?

Both statements have to be true for the console to output the "True" statement.

Upvotes: 0

Views: 195

Answers (2)

AliBZ
AliBZ

Reputation: 4099

if((a == b) && (c == d))
    System.out.println("True");

Upvotes: 7

Gus
Gus

Reputation: 6881

If a, b, c and d are objects you should do this

if ((a.equals(b) && c.equals(d)) {
  System.out.println("True");
}

If they are primitives such as (int, long etc. Strings are not primitives!) then use AliBZ's solution

(null checking left as an excercise for the reader)

Upvotes: 2

Related Questions