Answer:

Yes. There are other tests that divide the integers into these three groups. But you will always need two tests, whatever they are.

Number Tester Program

Here is a program that implements the flowchart. The part of the program that corresponds to the nested decision of the flow chart is in red. This is called a nested if statement because it is nested as part of a branch of another if statement.

import java.util.Scanner;

class NumberTester
{
  public static void main (String[] args)  
  {
    Scanner scan = new Scanner( System.in );
    int num;

    System.out.println("Enter an integer:");
    num = scan.nextInt();

    if ( num < 0 )
    {
      System.out.println("The number " + num + " is negative");    // true-branch

    } 
    else
    { 
      if ( num > 0 )
      {
        System.out.println("The number " + num + " is positive");  // nested true-branch
      } 
      else
      {
        System.out.println("The number " + num + " is zero");      // nested false-branch
      }

    }

    System.out.println("Good-bye for now");    // always executed
  }
}

 

QUESTION 16:

Could an if statement be nested inside the true branch of another if statement?