-2
這就像問題題目一樣。我遇到問題的區域是if/else屬性..還有,我將如何將其從API接口更改爲數組類型接口?對不起,如果我的格式很差。隨時糾正我。如何添加更多帳戶和輸出到我的密碼驗證程序?
程序糾正並運行它是如何打算:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner; // Needed for the Scanner class
public class PasswordVerifier2 {
public static void main(String[] args) throws FileNotFoundException {
Scanner keyboard = new Scanner(System.in);
String input;
System.out.print("Please enter your password: ");
input = keyboard.nextLine();
if (authenticate1(input)) {
System.out.println("This program is working if this text is found within outputfile.txt.");
File file = new File("outputfile.txt");
FileOutputStream fos = new FileOutputStream(file);
PrintStream ps = new PrintStream(fos);
System.setOut(ps);
System.out.println("This program is working if this text is found within outputfile.txt.");
}else if (authenticate2(input)) {
System.out.println("It works.");
}else{
System.out.println("Error: Wrong password.");
}
}
private static boolean authenticate1(String password1) {
return ((password1.length() == 6)
&& (password1.matches("beep11"))
&& (password1.matches("beep11"))
&& (password1.matches("beep11")));
}
private static boolean authenticate2(String password2) {
return ((password2.length() == 6)
&& (password2.matches("beep22"))
&& (password2.matches("beep22"))
&& (password2.matches("beep22")));
}
}
這將無法正常工作,並且我對驗證類fetchers有錯誤。回到原點1.在身份驗證2處仍然存在此錯誤。 – chaosillusion
我更新了代碼。現在我遇到了authentication2密碼所在的問題。我如何完成這項工作?主字符串中不再有錯誤。 – chaosillusion
我已經更新了答案。 –