I’m trying to solve a problem I’ve got on my homework.
How can I check if a value is within a range, e.g. 1 ≤ value ≤ 31, without using if, switch, or any other control structure, in Java?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See it run at http://ideone.com/98sA8.
You could even extend this to run different code paths:
See it run at http://ideone.com/sUKiW.