方式1:
//创建Scanner对象
Scanner sc = new Scanner(System.in);
System.out.print("请输入用户名:");
name = sc.nextLine();//读取键盘输入
System.out.print("请输入密码:");
password = sc.nextLine();//读取键盘输入
方式2:
//创建输入字符流
BufferedReader keyReader = new BufferedReader(new InputStreamReader(System.in));//这里用到了输入字节流转换字符流
System.out.print("请输入用户名:");
name = keyReader.readLine();//接受键盘输入
System.out.print("请输入密码:");
password = keyReader.readLine();//接受键盘输入