补全代码:PassWord.javaimport 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("输入密码:"); 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) {//从文件中读取数据 } }}
时间: 2023-06-16 09:02:50 浏览: 135
//补全代码如下:
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("输入密码:");
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) {
try {
File file = new File("password.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
fileReader.close();
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
注:上述代码中从文件中读取数据的部分需要根据具体需求进行修改。
阅读全文