java achieve input account number and password, there are three chances.

 Enter your account number or user name and password, if all three input error, then you have no chance

Format is as follows:

Please enter account / user name:

XXX

Please enter your password:

654321

You enter the wrong! ! ! Do you have "+2+" chance

........

code show as below:

 

package JAVA;

import java.util.Scanner;

public class java4 {
      public static void main(String agrs[]) {
    	  Scanner input =new Scanner (System.in);
    	  for(int i=2;i>=0;i--) {
    		  System.out.print("请输入账号/用户名:");
    		  String name =input.next();
    		  System.out.print("请输入密码:");
    		  int password=input.nextInt();
    		  if(name.equals("小明")&&password==123456) {
    			  System.out.println("欢迎你,会员大佬");
    			  break;
    		  }else
    			  System.out.print("你输入错误!!!你还有"+i+"次机会");
    		      System.out.println();
    		      if(i==0) {
    		    	  System.out.print("三次全错!你没有机会了!");
    		      }
    	  }
      }
}

 

Published 31 original articles · won praise 11 · views 761

Guess you like

Origin blog.csdn.net/shnagmiao/article/details/104745738