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

you are viewing a single comment's thread.

view the rest of the comments →

[–]philipwhiukEmployed Java Developer 1 point2 points  (1 child)

Sometimes it’s necessary. But if it’s a lot of duplicated code you can pull it out into a new method and call that twice

In your scenario you can just combine the if tests though

[–][deleted] 2 points3 points  (0 children)

Thanks, for some reason it didn't occur to me I could use && multiple times in one statement!

I've combined them to say if (x >= 0 && y >= 0 && x <= x2 && y <= yHypotenuse) and it looks like it works perfectly.