System.in.read() && java.io.IOException

时间:2020-05-20 17:06:12   收藏:0   阅读:46

 

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值

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!