1.问题( E) o: c" N9 j9 H' R( k0 T
日常生活中我们会遇到许多需要密码来登录账户的场景,如何使用Java来创建此类登录代码呢?7 E9 E- L- A5 I8 A. z2 ^0 R
2.方法
2 U) B( O7 y" U8 y! ?# C1 p% X1 s5 nimport java.util.Scanner;
public static void main (String[] args) {
Scanner sc = new Scanner (System.in);
int count = 3;
while(count›0){
System.out.println(“请输入密码: ");
String password = sc.nextLine();
if(password.equals(“123456” )){
System.out.printin(“输入正确,登录成功 ");}
else{
count --;
System.out.println(“输入错误,”+“你还有"+count+“次机会");
}
}
} 3.结语
' Q9 m6 g6 j4 | f# p: x" A' } 针对登录系统的使用问题,我们发现是可以使用Java来进行实现,并设定输错密码3次自动锁定的保护程序,证明此方法是有效且实用的。 |