A good answer might be:

The complete program can use nearly the same code for the next two numbers as for the first number.

Complete Program

Here is the complete program. The differences in the code for each of the three numbers is highlighted in color. Noticing similarites like this between sections of code will often lead to better programs.

import java.io.*;

class ComboLock
{
  public static void main ( String[] args ) throws IOException
  {
    int lockFirst = 6, 
        lockSecond = 12, 
        lockThird = 30;  // The combination
    int numb;            // a user-entered number

    BufferedReader stdin = new BufferedReader( 
        new InputStreamReader( System.in ) );
    String input;

    boolean correct = true;

    //First Number
    System.out.println("Enter first number: ");
    input = stdin.readLine();
    numb  = Integer.parseInt( input );

    if ( numb != lockFirst )    
      correct = false ;

    //Second Number
    System.out.println("Enter second number: ");
    input = stdin.readLine();
    numb  = Integer.parseInt( input );

    if ( numb != lockSecond )    
      correct = false  ;

    //Third Number
    System.out.println("Enter third number: ");
    input = stdin.readLine();
    numb  = Integer.parseInt( input );

    if ( numb != lockThird )    
      correct = false  ;

    //Result
    if ( correct )
      System.out.println("Lock opens");
    else
      System.out.println("Lock does not open");
  }
}


QUESTION 7:

There are 4 if statements in this program. Are these if statements nested? (That is: is any if statement part of the true branch or the false branch of another?)