title: Java if else with nested loop
body: <p>I am having some problem with my java assignment and currently am stuck at the nested if else statement.I am actually trying to get an input age from the user and store in as a variable.After executing my code i am getting error when i run the program.Am i doing this correctly or is there some other way to program this?</p>
  
  <p>Error message that i got</p>
  
  <pre>
      Enter your selection: 
      1
      You have selected No.1
      Please enter your age**Exception in thread "main" 
      java.lang.IllegalStateException: Scanner closed
      at java.util.Scanner.ensureOpen(Unknown Source)
      at java.util.Scanner.next(Unknown Source)
      at java.util.Scanner.nextInt(Unknown Source)
      at java.util.Scanner.nextInt(Unknown Source)
      at Assignment.main(Assignment.java:48)**
  </pre>
  
  <pre><code>public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      System.out.println(
         "1. Add player" + "\n" +
         "2.Display transaction" + "\n" +
         "3.Begin the ride");
      System.out.println("");
      System.out.println("Enter your selection: ");
      char selection = sc.findInLine(".").charAt(0);
      sc.close();
      switch(selection)  {
      case '1' :
          System.out.println("You have selected No.1");
          break;
      case '2' :
          System.out.println("You have selected No.2" );
          break;
      case '3' :
          System.out.println("You have selected No.3" );
          break;  
      default: 
          System.out.println("Please make a selection");
          break; 
     }
     if (selection=='1') {  
          int age=0;
          System.out.print("Please enter your age");
          age = sc.nextInt();
          while (age&lt;100) {
              age+=age;
          }
      }       
      else if (selection=='2') {
          System.out.println("Display daily transaction");
      }
      else if (selection=='3') {
          System.out.println("Begin the ride");
      }
      else {
          System.out.println("Please enter a valid input");
      }
  }
  </code></pre>