[java]代码库
/*
* scanner: 输入
*/
//构造一个scanner对象
Scanner in = new Scanner(System.in);
//get string input, and first word
System.out.println("What is your name?");
String name = in.nextLine();
//get integer input
System.out.println("How old are you?");
int age = in.nextInt();
System.out.println("Name: "+name);
System.out.println("Age: "+age);
System.out.println("Please input:");
if(in.hasNext("yes"))
{
System.out.println("yes......");
} else
{
System.out.println("no......");
}
/*
* console: 输入是看不到,看以设置为密码。
*/
import java.io.Console;
public class HelloJava{
public static void main(String[] args){
Console console = System.console();
String password = new String(console.readPassword());
System.out.println("password="+password);
}
}
/*
#运行结果
[root@hzvscmdb java]# java HelloJava
password=123work
#注意
char[] passwd = cons.readPassword("Password: "); //为了安全起见,返回的密码存放在一维字符数组中,而不是字符串中。
*///源代码片段来自云代码http://yuncode.net