程序如下:import java.io.*;
public class Password{
public static void main( String args[ ]) {
boolean success = false;
int count = 0;
Console cons;
// char[] passwd;
cons = System.console();
while(true) {
System.out.print("输入密码:");
char[]passwd = cons.readPassword();
count++;
String password=new String (passwd);
if (password.equals("tiger123")) {
success= true;
System.out.println("您第" + count + "次输人的密码正确!");
break;
}
else {
System.out.println("您第" + count + "次输人的密码" + password + "不正确");
}
if(count == 3) {
System. out. println("您" + count + "次输人的密码都不正确");
System.exit(0);
}
}
if(success) {
File file = new File( "score, txt");
try {
FileReader inOne = new FileReader(file);
BufferedReader inTwo= new BufferedReader(inOne);
String s= null;
while( (s = inTwo.readLine())!= null) {
System.out.println(s);
}
inOne.close();
inTwo.close();
}
catch (IOException exp) {}
}
}
}
程序没有报错,可是会出现下面的问题,请教一下,到底是什么原因(下面的异常我懂),就是不知道怎么改。
public class Password{
public static void main( String args[ ]) {
boolean success = false;
int count = 0;
Console cons;
// char[] passwd;
cons = System.console();
while(true) {
System.out.print("输入密码:");
char[]passwd = cons.readPassword();
count++;
String password=new String (passwd);
if (password.equals("tiger123")) {
success= true;
System.out.println("您第" + count + "次输人的密码正确!");
break;
}
else {
System.out.println("您第" + count + "次输人的密码" + password + "不正确");
}
if(count == 3) {
System. out. println("您" + count + "次输人的密码都不正确");
System.exit(0);
}
}
if(success) {
File file = new File( "score, txt");
try {
FileReader inOne = new FileReader(file);
BufferedReader inTwo= new BufferedReader(inOne);
String s= null;
while( (s = inTwo.readLine())!= null) {
System.out.println(s);
}
inOne.close();
inTwo.close();
}
catch (IOException exp) {}
}
}
}
程序没有报错,可是会出现下面的问题,请教一下,到底是什么原因(下面的异常我懂),就是不知道怎么改。
解决方案 »
- 在string中如何实现对某个子母或单词的查找并输出要查找字段的首字母其在整个String中的索引位置?
- 大家觉得周惠英的JAVA书如何
- 怎么用循环比较数组内各数的大小
- Spring声明式事务中如何管理Session
- 如何使用itext在已经存在的pdf文件中添加bookmarks?
- 怎么判断一个txt文件的编码方式?比如判断它是ISO8859-1还是GBK
- 如何配置microsoft sql server 2000 driver for jdbc
- 图形的初级问题
- 我是新手,请多多关照!
- 哪有防反编译工具joc下载?谢谢
- 谁能帮我完成我的圣诞倒计时的未完成部分的代码?
- 发一个面试题:如何判断两个矩形有相交的部分?
eclipse你建的项目造成执行这个cons.readPassword()有问题。