本帖最后由 EggEgg 于 2015-5-25 21:35 编辑
package cn.itcast.chapter11;
import java.util.Scanner;
public class UserNameTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请设置用户名:");
String name = sc.nextLine();
System.out.println("请设置密码:");
String password = sc.nextLine();
for (int i = 0; i < 3; i++) {
System.out.println("请设置用户名:");
String name1 = sc.nextLine();
System.out.println("请输入密码:");
String password1 = sc.nextLine();
if (name.equals(name1)&&password.equals(password1)) {
System.out.println("登陆成功");
break;
}
if (i == 2) {
System.out.println("账号已锁定,请找我解密码~");
break;
}
System.out.println("输入错误,你还有" + (2 - i) + "次机会");
}
}
}
|