/*
   This program demonstrates a common way to format
   the code when we have an if-else-statement nested in
   the else-clause of an if-else-statement. This format
   saves a lot of screen space and it makes the structure
   of the nested if-else-statements more clear.

   It is important to note that this is exactly the same program
   as in the file NestedIfElseStatements.java. The only thing
   that has been changed is where the line breaks are.

   This format is so common that it is often refered to as
   using nested "else-if" statements (or even "elif-statements").

   One way to think about this is that an if-else statement
   gives you the ability to specify two mutually exclusive
   bodies of code, only one of which gets executed. But what
   if you have three (or more) mutually exclusive bodies of
   code and only one of them should be executed? The nested
   "else-if" clauses let you specify as many addittional
   mutually exclusive blocks of code as you need. Only one of
   the else-if clauses (or the then-cluase or the else-clause)
   will get executed.

   The "else-clause" (which always comes after all the else-if
   clauses) is often thought of as a "catch-all" (or default)
   clause. Notice that the else-clause is the only clause without
   its own condition. The else-clause handles everything that
   evaluated all of the if-else clause conditions to false.
   (The final else-clause is actually optional, but it is
   almost always there.)
*/
import java.util.Scanner;

public class NestedIfElseStatements2
{
   public static void main( String[] args )
   {
       // Create a Scanner object that reads from the keyboard
       Scanner scanner = new Scanner(System.in);

       System.out.print("Please enter a decimal number: ");
       double xIn = scanner.nextDouble();

       if ( xIn < 0 )
          System.out.println("Your input was negative.");
       else if ( xIn <= 1 )
          System.out.println("Your input was between 0 and 1.");
       else if ( xIn <= 2 )
          System.out.println("Your input was between 1 and 2.");
       else if ( xIn <= 3 )
          System.out.println("Your input was between 2 and 3.");
       else if ( xIn <= 4 )
          System.out.println("Your input was between 3 and 4.");
       else
          System.out.println("Your input was larger than 4.");
   }//main

}//NestedIfElseStatements2