【发布时间】:2019-10-06 14:10:00
【问题描述】:
let the user get 3 attempts only, after it he get his account suspened我尝试要求用户提供 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");
}
}}
【问题讨论】:
-
你问的问题是什么?
-
使用一个循环,一个while循环。查找并试一试。
-
尝试在 if 语句中使用方括号
{ }。如果你没有,它只会执行 if 语句之后的下一行 -
@alea 你能说得更具体些吗?谢谢!
标签: java eclipse if-statement netbeans user-input