First, the procedure design thought:
The 1.for loop generates a six-character password, with each random character password converted by char to Math.random ().
2. Build the input and output form and set the prompt information.
3. Make the program run properly through the DO_WHILE structure and verify it again when validating the error.
Second, the Process flow chart:
Third, the source program:
Package Login;
Import java.awt. *;
import javax.swing.*;
Public class Login {
Public Static void Main (string[] args) {
TODO auto-generated Method stub
Generate Verification Code
Define an empty string
String result = "";
Cycle 6 times
int flag=0;
Do {
for (int i = 0; i < 6; i + +)
{
Generates an integer of type 97~122 int
int intval = (int) (Math. Random() * 26 + 97);
After casting intvalue to char after connecting to result
result = result + (char) intval;
}
Display the verification code, and prompt the user to enter a verification code
String Input=joptionpane. Showinputdialog (result+ "\ n Please enter the verification Code:");
if (Input.equals (Result))//Determine if the verification code is correct
{
Joptionpane. Showmessagedialog (null, "Verify the code is correct, verify success!") ",
"Results", Joptionpane. plain_message );
flag=1;
}
Else
{
Joptionpane. Showmessagedialog (null, "Verification code error, please verify again!") ",
"Results", Joptionpane. plain_message );
}
}while (flag==0);
Iv. Results of implementation:
(Repeat to verify until correct)
(The program stops running because the validation is successful.) )
Five, the experiment Summary:
1. Through the implementation of this verification code, again learned to use Math.random () to generate a random number, and then the type conversion, through the for loop to produce a six-bit character verification code.
2. The popup interface can be implemented, and classes can be defined, with the class. Size (int wide, int long) to set the block diagram.
Based on Randomstr.java: Use type conversion to generate a six-bit validation string.