- public class StringTest {
- public static void main(String[] args) {
- String username = "ice";
- String password = "83509161";
- //创建键盘录入对象
- Scanner sc = new Scanner(System.in);
-
- //for循环
- for (int x=1;x<=3;x++) {
- //请输入用户名
- System.out.println("请输入你的用户名:");
- String name = sc.nextLine();
- //请输入密码
- System.out.println("请输入你的密码:");
- String psd = sc.nextLine();
- if (username.equals(name) && password.equals(psd)) {
- System.out.println("登录成功");
- break;
- }
- if (3-x == 0){
- System.out.println("账号被锁定,无法再次输入");
- }
- else {
- System.out.println("登录失败,你还有"+(3-x)+"次机会");
-
- }
- }
-
- }
- }
复制代码 接着上一个帖子
|