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