Random generation of 4-bit verification code, the user input and verify that the input is correct, if the input error to generate a new verification code to allow users to re-enter, up to 5 times

Source: Internet
Author: User

1         //four-bit random verification code2Random ran=NewRandom ();3String str1 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXUZ";4         Char[] A=New Char[4];5          for(inti=0;i<4;i++)6         {7A[i]=str1.charat (Ran.nextint (62));8         }9         TenStringBuilder rzm1=NewStringBuilder (); One          for(inti=0;i<4;i++) A         { -Rzm1.append (A[i]);//Generate 4-bit authentication code -         } theSYSTEM.OUT.PRINTLN ("Authentication code is" +rzm1); -String rzm2=NewString (RZM1);//Convert authentication code to string -Scanner sc =NewScanner (system.in); -System.out.print ("Please enter the verification code");  +          -          for(intj=0;j<5;j++) +         { A             if(Sc.nextline (). Equals (rzm2)) at             { -SYSTEM.OUT.PRINTLN ("Input correct");  -             } -             Else -             { -                 if(j<4) in                 { -System.out.println ("Enter the verification code again");  to                 } +                 Else -                 { theSystem.out.println ("The number of inputs has run out"); *                 } $             }Panax Notoginseng         } -         

Random generation of 4-bit verification code, the user input and verify that the input is correct, if the input error to generate a new verification code to allow users to re-enter, up to 5 times

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.