Android Studio | Java | If Statements with 3+ variable comparisons using && or alternate options

I’m attempting the below:

if(p1S > p2S && p3S)

}

But the IDE doesn’t like the && here.

So, how would I compare these 3 ints to find the one with the highest value, thus moving forward.

Aka: If Int 1 is greater than int 2, and int 3, then do this. . .

I suspect I just don’t know the syntax well enough just yet. (I’ve only just started college for CS)

>Solution :

Is this what you want?

if(p1S > p2S && p1S > p3S)

}

The reason the previous code didn’t work is that the first part

if(p1S > p2S && p3S)

}

evaluates to:

if(boolean && p3S)

}

And you can’t do an && between a boolean and an int.

Leave a Reply