//Created By ybb Scanner scanner = new Scanner(System.in); int chance = 3; for (int i = 1; i <=chance; i++) { System.out.println("请输入用户名"); String name = scanner.next(); System.out.println("请输入密码"); int password = scanner.nextInt(); if ( name.equals("张三")&& password==666){ System.out.println("登录成功"); break; }else{ System.out.println("你还有"+(chance-i)+"次机会"); } }
注意点:
1,字符串对比要用equals
2,判断值相等要用==