Java test: Write a registration function

| - demand explanation

 

| - realization of ideas

 See the code comments

 

| - Content Code

 1 import java.util.Scanner;
 2 
 3 /**
 4  * @auther::9527
 5  * @Description: 第八题
 6  * @program: 多线程
 7  * @create: 2019-08-10 09:40
 8  */
 9 public class Eighth {
10     static Scanner scanner = new Scanner(System.in);
11 
12     public static void main(String[] args) {
13         Eighth eighth = new Eighth();
14         eighth.login();
15     }
16 
17     // method of registering a user name 
18 is      public  void Login () {
 . 19          String name = "" ;
 20 is          Boolean ISOK = to false ; // Flag is set out cycle, determining whether the exit loop 
21 is          int NUM = 0;    // set counter, if the password is ok, counter + 1, if the user name of the OK, the +1 counter, if the final value of the counter 2, it is determined that the flag the OK 
22 is          String passwords = "" ;
 23 is  
24          do {
 25              System.out.println ( "Please enter a user name, a user name of not less than 3, not more than 6" );
 26 is              String the receive = Scanner.next ();
 27             System.out.println ( "Please enter a password, the password length is not less than 6, and the two passwords must be consistent" );
 28              String the Receive1 = Scanner.next ();
 29              System.out.println ( "Please re-enter the password, the password must be entered twice same " );
 30              String receive2 = Scanner.next ();
 31 is              // by topic in claim digit account determination, the condition 
32              IF (receive.length ()> =. 3 ) {
 33                  // user name matches, counter + 1'd 
34 is                  name = the receive;
 35                  NUM = +. 1 ;
 36              } the else {
 37 [                  // if the user name does not meet the requirements of the length, the counter is cleared 
38                 0 = NUM ;
 39                  System.out.println ( "Enter your user name does not satisfy the rule, it is necessary to re-enter" );
 40              }
 41 is              IF (receive1.length ()> =. 6 ) {
 42 is                  IF (receive1.equals (receive2 )) {
 43 is                      passwords = the Receive1;
 44 is                      // password matches, counter + 1'd 
45                      NUM = +. 1 ;
 46 is                  } the else {
 47                      // If the passwords do not match, the counter is cleared 
48                      System.out.println ( " the two passwords do not match your input, please re-enter " );
 49                     0 = NUM ;
 50                  }
 51 is              } the else {
 52 is                  // If the password does not meet 6, the counter is cleared 
53 is                  NUM = 0 ;
 54 is                  System.out.println ( "your password length of less than 6, to re-enter" );
 55              }
 56 is              IF (NUM == 2 ) {
 57 is                  ISOK = to true ;
 58              }
 59          } the while (! ISOK);
 60          System.out.println ( "successful registration, the user name and password Remember" );
 61      }
62 }
Q8 - Register

 

| - operating results

 

Guess you like

Origin www.cnblogs.com/twuxian/p/11330818.html