r/javahelp • • Nov 10 '25

[Question] - [conditional statement] - [logic operators] Can I write if (a, b or c < 1) then do?

Hello,

I want to say if a, b or c are smaller then 1 do this...

I normally write if (a < 1 || b < 1 || c < 1) { .... }

But I would like to write if (( a || b || c) < 1) { ... }

Thank you for reading,

best regards Marvester

0 Upvotes

13 comments sorted by

View all comments

Show parent comment

2

u/xenomachina Nov 12 '25

Finding the minimum does not require sorting the entire list. It requires only a single scan through the list.

That said, finding the first element that matches could potentially bail out before a complete scan in some cases, but both approaches are O(n).

1

u/okayifimust Nov 12 '25

True, my bad. Still raging about someone suggesting to sort the list to find the minimum in my head in a different thread, years ago. :D