How to read a character from console in Java

1 Answer

0 votes
package javaapplication1;

import java.io.IOException;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        int ch;

        try {

            System.out.print("Enter a character: ");
            ch = System.in.read();
            System.out.println((char)ch);

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
           
run:
     
Enter a character: a
a
  
 */

 



answered Nov 22, 2016 by avibootz

Related questions

1 answer 183 views
1 answer 157 views
1 answer 139 views
139 views asked Oct 12, 2022 by avibootz
1 answer 122 views
1 answer 230 views
...