java编写密码、PIN和PUK程序
我试图创建一个程序,提示用户输入正确的密码。第三次未正确输入密码时,程序应向用户询问PIN,如果用户仍有3次未能正确输入PUK,则程序现在应打印SIM卡
我想我必须使用循环,但我不知道如何使用。我只是个新手
import java.util.Scanner;
import java.io.*;
public class PinPUK {
public static void main(String[] a) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter Pin Code: ");
int choice = keyboard.nextInt();
if (choice == 123) {
System.out.println("Welcome!");
}
else {
System.out.println("Password is incorrect! Try again!"); // This is the 1st time the wrong password has been entered.
} // 2 more and the program should ask for the PIN 3 times if incorrectly entered, and program should ask the PUK 3 times if it is incorrect, the program should now print SIM BLOCKED.
}
}
# 1 楼答案
请尝试以下方法:
输出1:
输出2:
输出3:
如果要将PIN与0进行比较,请使用以下选项:
然后在if语句中使用以下命令:
而不是
完整代码如下:
# 2 楼答案
# 3 楼答案
可以使用以下代码段完成此操作: