title: Java: Why this program works with char and not with int?
body: <p>I am learning java, and I came across one sample program in the book I am learning from. I decided to experiment a little and I don't understand why it doesn't work as expected. Program is very simple, it's a menu that should output general forms of some of Java's statements based on users input. Here's the code: </p>
  
  <pre><code>public class SimpleMenu {
  public static void main(String args[])
      throws java.io.IOException {
          int choice;
          do {
              System.out.println("Help on: ");
              System.out.println(" 1. IF");
              System.out.println(" 2. WHILE");
              System.out.println(" 3. DO WHILE");
              System.out.println(" 4. FOR");
              System.out.println(" 5. SWITCH\n");
              System.out.println("Choose one: ");
              choice = System.in.read();
          } while ((choice &lt; 1) || (choice &gt; 5));
          System.out.println("\n");
          switch (choice) {
              case 1:
                  System.out.println("if(condition) statement1;\n else statement2;");
                  break;
              case 2:
                  System.out.println("while(condition){\n //body of loop \n }");
                  break;
              case 3:
                  System.out.println("do{ \n //body of loop \n } while(condition);");
                  break;
              case 4:
                  System.out.println("for(initialization; termination; increment/decrement){ \n statement; \n }");
                  break;
              case 5:
                  System.out.println("switch(value){\n case 1: \n statement; \n break; \n default:\n statement;\n}");
                  break;
          }
      }
  }
  </code></pre>
  
  <p>No matter what number I type in, it goes through do-while loop two times and expects input again.
  This is the original code: </p>
  
  <pre><code>public class MenuFromBook {
  public static void main(String args[])
          throws java.io.IOException {
      char choice;
      do {
          System.out.println("Help on: ");
          System.out.println(" 1. if");
          System.out.println(" 2. switch");
          System.out.println(" 3. while");
          System.out.println(" 4. do-while");
          System.out.println(" 5. for\n");
          System.out.println("Choose one:");
          choice = (char) System.in.read();
      } while( choice &lt; '1' || choice &gt; '5');
      System.out.println("\n");
      switch(choice) {
          case '1':
              System.out.println("The if:\n");
              System.out.println("if(condition) statement;");
              System.out.println("else statement;");
              break;
          case '2':
              System.out.println("The switch:\n");
              System.out.println("switch(expression) {");
              System.out.println(" case constant:");
              System.out.println(" statement sequence");
              System.out.println(" break;");
              System.out.println(" //...");
              System.out.println("}");
              break;
          case '3':
              System.out.println("The while:\n");
              System.out.println("while(condition) statement;");
              break;
          case '4':
              System.out.println("The do-while:\n");
              System.out.println("do {");
              System.out.println(" statement;");
              System.out.println("} while (condition);");
              break;
          case '5':
              System.out.println("The for:\n");
              System.out.print("for(init; condition; iteration)");
              System.out.println(" statement;");
              break;
      }
  }
  </code></pre>
  
  <p>But I don't understand why it has to be done like that, why can't choice be int and work like that? I hope I was clear...</p>