import java.util.*; public class InputTest { public static void main(String[] args) { Scanner dx = new Scanner(System.in); //构造一个与Sytem.in相关联的Scanner对象 System.out.print("What is your name? "); String name = dx.nextLine(); //创建实例获取一行输入 System.out.print("How old are you? "); int age = dx.nextInt(); //创建实例获取int类型输入
/*
Double a = dx.nextDouble获取double类型输入
String a = dx.nextLine获取一行输入,以回车结束
String a = dx.line获取单词输入,以空格结束
*/ System.out.println("Hello, " + name + ". Next year, you'll be " + (age + 1)); } }
读取密码操作使用Console对象处理,一次读取一行输入