键盘在哪里指定了System.in方法? [英] Where is the keyboard specified the System.in method?

查看:56
本文介绍了键盘在哪里指定了System.in方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码(从键盘检索字符并打印到命令行)中,我不能从概念上理解我指定输入必须来自键盘的地方?

I can't conceptually understand in the below code (that retrieves characters from keyboards and prints to the command line) where I specified that input must come from the keyboard?

public class Adder
{
    public static void main(String arr[])
    {

        //Explain this next line, please:
        Scanner in = new Scanner(System.in);    
        System.out.println("Enter First No.");    
        int a = in.nextInt();    
        System.out.println("Enter Second No.");    
        int b = in.nextInt();    
        int c = a+b;    
        System.out.println("Sum is: "+c);    
    }    
}

推荐答案

System.in 不是方法,默认情况下,它是与键盘绑定的字段.

System.in isn't a method, it's a field that's tied to your keyboard by default.

标准"输入流.该流已经打开,可以提供输入数据了.通常,此流对应于键盘输入或主机环境或用户指定的另一个输入源.

The "standard" input stream. This stream is already open and ready to supply input data. Typically this stream corresponds to keyboard input or another input source specified by the host environment or user.

您可以调用

You can call the System.setIn(InputStream in) method to change it to a different input stream.

参考:从命令行输入/输出

这篇关于键盘在哪里指定了System.in方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆