1. Design Ideas
First, name name, enter a name and password with a message box, then use the type conversion to generate a six-bit verification string, enter the verification code with the message box, and then determine if the input verification code is correct, if the correct display verification is successful, if the failure shows verification failure re-enter the name password verification code, until the input is correct.
2. Program Flowchart
3. SOURCE program
Package Lab task four;
Import Java.util.Scanner;
Import Javax.swing.JOptionPane;
public class Randomstr
{
public static void Main (string[] args)
{
String name;//defines the login name
String number;//Definition Verification Code
String mima;//defines the password
int q=0;//defines a number that is used to determine whether to jump out of a loop
Do
{
Name=
Joptionpane.showinputdialog ("Please enter login name:");//message box Enter login name
Mima=
Joptionpane.showinputdialog ("Please enter password:");//message box enter password
Define an empty string
String result = "";
Cycle 6 times
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;
}
Number=
Joptionpane.showinputdialog ("Verification Code" +result);//message box output verification code and enter a verification code,
Output random string
if (number.equals (Result))//Determine the input verification code and give the verification code is consistent
{
Joptionpane.showmessagedialog (
NULL, "Validation succeeded", "Results",//output validation successful in message box
Joptionpane.plain_message);
Q=1;
}
if (!number.equals (Result))//Determine the input verification code and the given verification code is consistent
{
Joptionpane.showmessagedialog (
NULL, "Captcha error, re-enter", "Results",//output sum in message box
Joptionpane.plain_message);
}
}while (q!=1);//When the CAPTCHA input is correct, it jumps out of the loop
}
}
4. Results
5. Experimental summary
This program does not appear as required by the overall landing page, I put them in the form of a message box to sign in. In this program I learned that Java randomly generated an integer, but also to edit the message box code more familiar with, Next, I will learn how to display the overall landing page.
Java Landing Interface Experiment Report