需要调用Scanner类
Scanner in = new Scanner(System.in); //Scanner类
in.nextLine(); // return String regardless of space
in.next(); // return String , split with space
in.nextInt(); //return int
in.nextDouble(); //return double
in.hasNext(); //return boolean
in.hasNextInt(); //return boolean
in.hasNextDouble(); //return boolean
不可见输入
Console cons = System.console();
String username = cons.readLine("User name: ");
char[] password = cons.readPassword("Password: ");
本文详细介绍了Java中Scanner类的各种使用方法,包括如何读取不同类型的输入数据如字符串、整数和浮点数等,并提供了不可见输入的替代方案。
398

被折叠的 条评论
为什么被折叠?



