title: How to take single character input from user in Java?
body: <p>In the below example , I am trying accept single character input from user, but when running the program, I get do..while loop executed multiple times. Please see the result of the program below.</p>
  
  <p>If some one could help me with the answer, how to fix this problem?</p>
  
  <pre><code>import java.io.*;
  
  
  
  public class Main {
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) throws IOException {
  
  
  
              char c;
             // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
              DataInputStream in =new DataInputStream(System.in);
  
              // Asking the user what to do with the application
             do{ 
  
              System.out.println("Would you like to access your account, if yes,type 'Y' or if you want to create a new account press 'N'to exit press 'E' ");          
  
              byte b = in.readByte();
              c = (char) b;
              c = Character.toUpperCase(c);
  
              if (c=='Y'){
                  System.out.println(c);
                 }
              else if (c=='N') {
                System.out.println(c);
              }
              else if (c=='E'){
                 System.out.println(c); 
              }
              else{
                  System.out.println("Incorrect Entry, try again: "+c); 
              }
  
             }while (c!='E');
  
      }
  
  }
  </code></pre>
  
  <h1>Output</h1>
  
  <pre><code>init:
  deps-jar:
  compile:
  run:
  Would you like to access your account, if yes,type 'Y' or if you want to create a new account press 'N'to exit press 'E' 
  asdfgaf
  Incorrect Entry, try again: A
  Would you like to access your account, if yes,type 'Y' or if you want to create a new account press 'N'to exit press 'E' 
  Incorrect Entry, try again: S
  Would you like to access your account, if yes,type 'Y' or if you want to create a new account press 'N'to exit press 'E' 
  Incorrect Entry, try again: D
  Would you like to access your account, if yes,type 'Y' or if you want to create a new account press 'N'to exit press 'E' 
  Incorrect Entry, try again: F
  Would you like to access your account, if yes,type 'Y' or if you want to create a new account press 'N'to exit press 'E' 
  Incorrect Entry, try again: G
  Would you like to access your account, if yes,type 'Y' or if you want to create a new account press 'N'to exit press 'E' 
  Incorrect Entry, try again: A
  Would you like to access your account, if yes,type 'Y' or if you want to create a new account press 'N'to exit press 'E' 
  Incorrect Entry, try again: F
  Would you like to access your account, if yes,type 'Y' or if you want to create a new account press 'N'to exit press 'E' 
  Incorrect Entry, try again: 
  
  Would you like to access your account, if yes,type 'Y' or if you want to create a new account press 'N'to exit press 'E' 
  </code></pre>