/** * Nested if demo * @author Pete Nordquist * @version 180121 - uses TextIO **/ public class W02N02 { public static void main( String[] args) { // declare variables double d; double mod; // get number System.out.print("Your double> "); d = TextIO.getlnDouble(); // if d is negative if (d < 0) { // print message that it was negative System.out.println(d + " is negative."); } // otherwise else { // if the users number is between 0 and 100, inclusive, // if the number is <= 100 if (d <= 100) { // print it. System.out.println("Input number, " + d + ", between 0 and 100 inclusive"); } // otherwise else { // modulate the number // permissible to use a non-if statement here, // because all code from here to the end of // the nested if requires that the variable mod // be assigned a value mod = d % 100; // if the modulated result is between 50 and 100 (non-inclusive) // I already know mod is < 100, by the definition of modulo, so // if modulated result > 50 it is in the range I want to print if (mod > 50) { System.out.println("modulated number " + d + " is between 50 and 100"); } } } } }