首页 > 编程语言 > 详细

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

时间:2020-05-20 17:31:42      阅读:42      评论:0      收藏:0      [点我收藏+]

 

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值

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

原文:https://www.cnblogs.com/profesor/p/12924683.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!