//输入一个大于0的数,否则一直循环
public static void test1() {
System.out.println("请输入一个数");
for (; true; ) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
if (a > 0) {
System.out.println("欢迎进入");
break;
} else {
System.out.println("请输入一个正整数");
}
}
}
//输入账号和密码,三次错误就退出
public static void test2() {
String name = "哈哈哈";
String passworld = "123456";
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 3; ) {
System.out.println("请输入你的账号");
String name2 = sc.next();
System.out.println("请输入你的密码");
String world = sc.next();
if (name2.equals(name) && world.equals(passworld)) {
System.out.println("欢迎");
break;
} else {
System.out.println("请重新输入,你还有" + (3 - i) + "次机会");
i++;
}
}
}