注意以下代码要在dos运行
在eclipse下运行时报NullPoint指针,可能要把运行环境调整console才好
import
import
import
import java.util.*;
public class Password {
public static void main(String[] args) throws IOException {
System.out.println("--欢迎进入学员注册系统--");
Scanner input = new Scanner(System.in);
System.out.print("请输入您的账号:");
String zhanghao = input.next();
Console con = System.console();
System.out.print("请输入您的密码:");
String possword1 = new String(con.readPassword());
System.out.print("请确认您的密码:");
String possword2 = new String(con.readPassword());
if (possword1.equals(possword2)) {
String mima = possword1 = possword2;
System.out.println("恭喜您,注册成功!!!");
System.out.println("您的账号是: " + zhanghao + "您的密码是: " + mima
+ "\n请记好的您的账号和密码,以防遗忘!!! ");
} else {
System.out.println("密码不一致,请重新注册!!!");
}
}
}
[/code]console下只能到不显示密码了, 如果想用"*"替代字符,暂时不能用纯java实现[/b]
[ 本帖最后由 usbboy2009 于 2009-8-9 10:29 编辑 ]
在eclipse下运行时报NullPoint指针,可能要把运行环境调整console才好
import
import
import
import java.util.*;
public class Password {
public static void main(String[] args) throws IOException {
System.out.println("--欢迎进入学员注册系统--");
Scanner input = new Scanner(System.in);
System.out.print("请输入您的账号:");
String zhanghao = input.next();
Console con = System.console();
System.out.print("请输入您的密码:");
String possword1 = new String(con.readPassword());
System.out.print("请确认您的密码:");
String possword2 = new String(con.readPassword());
if (possword1.equals(possword2)) {
String mima = possword1 = possword2;
System.out.println("恭喜您,注册成功!!!");
System.out.println("您的账号是: " + zhanghao + "您的密码是: " + mima
+ "\n请记好的您的账号和密码,以防遗忘!!! ");
} else {
System.out.println("密码不一致,请重新注册!!!");
}
}
}
[/code]console下只能到不显示密码了, 如果想用"*"替代字符,暂时不能用纯java实现[/b]
[ 本帖最后由 usbboy2009 于 2009-8-9 10:29 编辑 ]