Java Reader read a character from console

Description

Java Reader read a character from console

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;

public class Main {
   public static void main(String args[]) throws IOException {
      Reader cin = new InputStreamReader(System.in);
      System.out.println("Enter characters, 'q' to quit.");
      char c;/*from   w w w .j  a  v a 2  s .c om*/
      do {
         c = (char) cin.read();
         System.out.print(c);
      } while (c != 'q');
      cin.close();
   }
}



PreviousNext

Related