How to implement a registration function in Java
This article mainly introduces Java how to achieve a registration function, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Code content
Register
Import java.util.Scanner;/** * @ auther::9527 * @ Description: question 8 * @ program: multithreading * @ create: 2019-08-10 09:40 * / public class Eighth {static Scanner scanner = new Scanner (System.in); public static void main (String [] args) {Eighth eighth = new Eighth (); eighth.login ();} / method for registering a user name public void login () {String name = "" Boolean isOK = false; / / set the flag bit to jump out of the loop and determine whether it is possible to exit the loop int num = 0; / / set the counter, if the password ok, counter + 1, if the user name OK, counter + 1, if the final counter value is 2, then determine the flag bit OK String passWords = "" Do {System.out.println ("Please enter a user name with no less than 3 digits and no more than 6 digits"); String receive = scanner.next (); System.out.println ("Please enter a password whose length is not less than 6 digits, and the two passwords must be the same"); String receive1 = scanner.next () System.out.println ("Please enter the password again, the two passwords must be the same"); String receive2 = scanner.next (); / / determine the number of account digits according to the title requirements, meet the condition if (receive.length () > = 3) {/ / the user name meets the condition, counter + 1 name = receive; num + = 1 } else {/ / if the user name length does not meet the requirements, the counter clears zero num = 0; System.out.println ("the user name you entered does not meet the rules, you need to re-enter it");} if (receive1.length () > = 6) {if (receive1.equals (receive2)) {passWords = receive1 / / the password matches the condition, counter + 1 num + = 1;} else {/ / if the password entered twice is inconsistent, the counter clears System.out.println ("the password you entered twice is inconsistent, please re-enter it"); num = 0 }} else {/ / if the password does not meet 6 digits, the counter clears num = 0; System.out.println ("your password is less than 6 digits, you need to re-enter");} if (num = = 2) {isOK = true;}} while (! isOK) System.out.println ("register successfully, please remember the user name and password");}} run result Thank you for reading this article carefully. I hope the article "how to achieve a registration function of Java" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!