三种从键盘输入的方式

1.通过Scanner进行输入

        Scanner w1 = new Scanner(System.in);
        System.out.println("请输入一个整型值:");
        int c = w1.nextInt();//输入0
        System.out.println(c);//0

2.通过System.in.read来进行读入数据

        System.out.println("请输入一个整型值:");
        int a = System.in.read();//输入0
        System.out.write(a);//0,字符流,只是输出改变,里面逻辑值仍错误
        System.out.println();//换行
        System.out.println(a);//48,字节流

解决方法即为用System.out.write();和方法3。
System.out.println();与System.out.write();的区别,参考
https://blog.csdn.net/raycode/article/details/5726460

3.用BufferedReader来读入数据

    System.out.println("请输入一个整型值:");
    BufferedReader w=new BufferedReader(new InputStreamReader(System.in));
    int b = Integer.parseInt(w.readLine());//输入0
    System.out.println(b);//0

参考:https://blog.csdn.net/jjchack/article/details/44416349

原创文章 42 获赞 32 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_39671159/article/details/80178327