Based on Randomstr.java: Use type conversion to generate a six-bit validation string.

Source: Internet
Author: User

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.

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.