集册 Java实例教程 readChar()方法从标准输入读取一个字符的类

readChar()方法从标准输入读取一个字符的类

欢马劈雪     最近更新时间:2020-01-02 10:19:05

451
readChar()方法从标准输入读取一个字符的类

import java.io.IOException;


public class Main {

  public static void main(String[] args) {
  /* 
   来自 
  *NowJava.com - 时代Java*/

    System.out.print("Enter some text and press Enter key: ");

    char c = readChar();

    System.out.println("First character you entered is: " + c);

  }

  public static char readChar() {

    char c = '\u0000';

    int input = 0;

    try {

      input = System.in.read();

      if (input != -1) {

        c = (char)input;

      }

    }/**来 自 时   代     Java  公  众  号 - nowjava.com**/

    
展开阅读全文