让用户只尝试 3 次,之后他的帐户就会被暂停我尝试要求用户提供最终密码 3 次,如果他没有这样做,就会告诉他他的帐户被暂停,如果正确的话会给他一条刺耳的消息。
package EE;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
final String password= "Test";
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the password: ");
String pass = sc.next();
for (int i=0; i<2;) {
if (!pass.equals (password))
i++;
System.out.println("Try again! ");
String pass1 = sc.next();
if(pass.equals( password))
System.out.println("Welcome");
String pass2 = sc.next();
if (i == 2)
System.out.println("Sorry, your account is suspened");
}
}}
桃花长相依
相关分类