System.in.read() && java.io.IOException
import java.io.IOException; public class Test { public static void main (String[] args) throws IOException { char a = (char) System.in.read(); //默认接受int,如果需要输出char,需要type cast int b = System.in.read(); //这里就不需要type cast了 System.out.println("a = " + a); System.out.println("b = " + b); } }
运行程序, 仅输入a, 然后回车,会得到
a = a;
b = 10; // 对应的是line feed的ASCII值