1 /* 2 * 三次登录机会 3 * */ 4 import java.util.Scanner; 5 6 public class WhileTest { 7 public static void main(String[] args) { 8 Scanner sc = new Scanner(System.in); 9 int i = 3; 10 while(i >= 1){ 11 System.out.println("用户名:"); 12 String UserName = sc.next(); 13 System.out.println("密码:"); 14 String PWD = sc.next(); 15 if(UserName.equals("yang") && PWD.equals("cheney")){ 16 //flag = true ; 17 System.out.println("登录成功,正在进入系统,请稍后......"); 18 break; 19 }else if(i == 1){ 20 System.out.println("今天输入错误次数过多,请24小时之后重试。。。"); 21 }else if(i >= 2){ 22 System.out.println("用户名或密码错误,您今天还有" + (i-1) + "次机会" ); 23 i-- ; 24 } 25 } 26 } 27 28 }