代码之家  ›  专栏  ›  技术社区  ›  Esc

使用记事本在Java中添加

  •  -2
  • Esc  · 技术社区  · 8 年前
    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);
       }
    }
    

    在代码中,有人能解释一下吗? 这将是明智的

    1 回复  |  直到 8 年前
        1
  •  0
  •   kkica    8 年前

    System in=new Scanner() 创建一个扫描仪对象,帮助您从系统的输入流、文件中读取数据。在参数中告诉 在里面 如果要读取文本文件,应创建一个文件对象,将文件路径作为参数,并将文件对象作为参数传递给 对象像这样的 Scanner in = new Scanner(new File("file.txt"));