title: Entering character for switch statement selection
body: <p>This question is regarding switch statement. These are a few similar posts on this (below) but I am still having trouble understanding.</p>
  
  <p><a href="https://stackoverflow.com/questions/14676248/using-user-inputted-characters-in-if-switch-statements">Using user-inputted characters in If/Switch statements</a></p>
  
  <p><a href="https://stackoverflow.com/questions/6906001/how-do-i-used-a-char-as-the-case-in-a-switch-case">How do I used a char as the case in a switch-case?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/14611084/multiple-characters-in-a-switch-statement">Multiple characters in a switch statement?</a></p>
  
  <p>Please consider the following:</p>
  
  <pre><code>public class main
  {
      public int selection; 
  
      public main()
      {
          System.out.println("MENU");
          Scanner in = new Scanner(System.in);
          do {
              showMenu();
              selection = in.nextInt();
              switch (selection)
              {
                  case 1:
                      doSomething();
                  break;              
                  case 2:
                  case 3: 
  
                  default: 
                      System.out.println("Instruction is invalid");
              }
          } 
          while (selection !=7);
          { System.exit(0); }
  }
  
  public static void showMenu() 
      {
          System.out.print('\u000c');
          System.out.println("option 1 \n");
          System.out.println("option 2 \n");            
          System.out.println("7 - exit.\n");
          System.out.println("Select Option:\n");
      }
  }
  </code></pre>
  
  <p>So this is a switch statement is for the user to choose options within the do while loop. The user enters an integer from the printed list to choose an option, after completion of the case, it loops back to menu. </p>
  
  <p>My teacher informs me that its better practice to use char instead of int to get user input for the switch. I expect it to look something like this, but it doesn't work and I'm not sure why. </p>
  
  <pre><code>public class main
      {
      public int selection; 
  
      public main()
      {
          System.out.println("MENU");
          Scanner in = new Scanner(System.in);
          do {
              showMenu();
              String menu = "";
              char selection = menu.charAt();          
              switch (selection)
              {
                  case 'A':
                  doSomething();
                  break;                
                  case 2, 3, 4, 5, 6
                  default: 
                  System.out.println("Instruction is invalid");
              }
          } 
          while (selection != 'QQ');
          { System.exit(0); }
  }
  </code></pre>
  
  <p>In the second link posted there was an answer which i think suggested using 
        hello.charAt(0)
  as the switch condition?</p>
  
  <pre><code>  switch (hello.charAt(0)) 
        {
            case 'a': ... break;
        }
  </code></pre>
  
  <p>I have three specific questions on this code:</p>
  
  <p>1) My code doesn't work. Should my condition be hello.charAt(0) ?</p>
  
  <p>2) I would like to use QQ as the quit option on the switch. Is possible with the code above? From the second link, I think it should be fine.</p>
  
  <p>3) It is also shown here (<a href="https://stackoverflow.com/questions/12809355/switch-statement-using-char-in-the-case-condition">switch statement using char in the case condition?</a>) that the case statement should have double quotations. Could someone please clarify this as well?</p>