Skip to content

August 7, 2014

Check if Two Numbers are Within a Range in Java

by admin

Let’s say we have two floating point numbers x and y and we want to check if those numbers are between 0 and 1 but not equal with either 0 and 1:

package learn_java;
 
public class Learn_java {
 
    public static void main(String[] args) {
        double x = 0.10;
        double y = 0.20;
        boolean isBetween01;
 
        isBetween01 = (x > 0 && x < 1) && (y > 0 && y < 1);
        System.out.println(isBetween01);
 
    }
}
Read more from Java Examples

Leave a Reply

required
required

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments