Scanner-扫描器

来源:互联网 发布:淘宝店铺如何免费推广 编辑:程序博客网 时间:2024/05/17 08:35

//java.util.Scanner包是JDK自带的
import java.util.Scanner;

class ScannerDemo{

public static void main(String []args){    //创建对象Scanner    Scanner sc = new Scanner(System.in);    //扫描器对象,获得我们从键盘输入的int值,sc调用nextInt()时候JVM就会等着我们输入    int a = sc.nextInt();    System.out.println("a的变量值"+a);    int b = sc.nextInt();    System.out.println("b的变量值"+b);    int result = sum(a,b);    System.out.println("a+b的和"+result);}public static int sum(int a,int b){    return a + b;}

}