使用记事本在 Java 中添加

Addition in Java using Notepad

class Addition
{
   public static void main(String[]args)
  {
    int x, y, z;
    System.out.printIn("Enter two integers to calculate their sum");
    Scanner in = new Scanner(System.in);
    x = in.nextInt();
    y = in.nextInt();
    z = x + y;
    System.out.printIn("Sum of enetered Integers="+z);
   }
}

我在某处看到过这个,但我无法理解它的用途 Scanner in = new Scanner(System.in);在代码中,有人能解释一下吗? 它会被应用

System in=new Scanner() 创建一个 Scanner 对象,帮助您读取输入流、文件... System.in 参数告诉 in 对象读取默认输入流,通常是您的键盘。 如果你想从文本文件中读取,你应该创建一个以文件路径作为参数的文件对象,并将文件对象作为参数传递给 Scanner 对象。像这样 Scanner in = new Scanner(new File("file.txt"));