开发者社区> 问答> 正文

输入的行为不符合预期,java FileReader

我有以下代码,该代码在执行时应从指定的文件中获取输入整数,并输出给定​​数字的乘法表最多10个。

现在我不知道为什么,但是当读取数字时,它将转换为完全不同的东西。

输入为3,文件识别为num。

有什么好猜测,怎么回事,我没看到?

public class exercise2 {
    public static void main(String[] args) {
        try {
            FileReader reader = new FileReader("e://ex2.txt");
            int num = reader.read();
            for (int i=0; i<11; i++){
                System.out.println(num + " * " + i+ "= "+ num*i);
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

展开
收起
垚tutu 2019-11-28 22:31:43 874 0
1 条回答
写回答
取消 提交回答
  • #include

    Reader.read 读取单个字符。

    该字符3具有Unicode代码点51(十进制)。

    2019-11-28 22:31:52
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载