Scanner in = new Scanner(System.in);

时间:2014-06-10 15:24:09

标签: java

public class Adder
{
public static void main(String arr[])
    {
    //System.in represents Standard Input Device (Keyboard)
    //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);    
    }    
}

我刚开始学习JAVA,我遇到了这段代码。有人可以解释一下标记的行是什么意思吗?

1 个答案:

答案 0 :(得分:2)

Scanner s=new Scanner(System.in);

上面代码中的System.in告诉编译器获取键盘输入的数据,这是一个输入设备

谢谢,

有关java中更基本的内容请查看: Tutorialspoint.com