1.题目
2.代码
import java.util.Scanner;
public class StringDemo3 {
public static void main(String[] args) {
//创建用户名和密码 这两个字符串
String rightUsername = "zhangsan";
String rightPassword = "123456";
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
//录入用户名和密码
System.out.println("请输入用户名");
String username = sc.next();
System.out.println("请输入密码");
String password = sc.next();
//比较
if(username.equals(rightUsername)&&password.equals(rightPassword)){
System.out.println("用户登录成功");
break;
}
else {
if(i==2){
System.out.println("账号"+username+"被锁定,请联系后台客服工作人员xxx-xxxxxx");
}else{
System.out.println("用户登录失败,用户名或密码错误,您还有"+(2-i)+"次机会");
}
}
}
}
}
3.快捷键
Ctrl+Alt+V--------快速创建对象
例:sc.next() 用快捷键后直接出来
Ctrl+Alt+L-------将代码格式化