package Com.luo;
Import Java.util.Scanner;
public class Login {public static void main (string[] args) {String username = "Luoluo";
String password = "123456";
for (int i = 0;i < 3;i++) {Scanner sc = new Scanner (system.in);
System.out.println ("Please enter user name:");
String name = Sc.nextline ();
System.out.println ("Please enter password:");
String pwd = Sc.nextline ();
if (name.equals (username) && pwd.equals (password)) {System.out.println ("login successful, start guessing word game");
Playgussnumber.start ();
}else{if ((2-i) ==0) {System.out.println ("Your account is locked");
}else{System.out.println ("Login failed, you also have" + (2-i) + "secondary opportunity");; }
}
}
}
}
Package Com.luo;
Import Java.util.Scanner;
public class Playgussnumber {
private Playgussnumber () {} public
static void Start () {
int # = (int) (Math . Random () *100+1);
while (true) {
System.out.println ("Please enter the number you want to guess (1-100):");
Scanner s = new Scanner (system.in);
int gussnumber = S.nextint ();
if (gussnumber>number) {
System.out.println ("You guessed the number" +gussnumber+ "guess Big");
} else if (gussnumber<number) {
System.out.println ("You guessed the number" +gussnumber+ "guess small");
} else{
System.out.println ("Congratulations, guessed right");
Break;}}}
Run Result:
Please enter user name:
Luoluo
Please enter a password:
Login failed, you still have 2 chances
Please enter user name:
Please enter a password:
Login failed, you have 1 more chances
Enter your username:
Luoluo
Please enter a password:
123456
Login Successful, start guessing the word game
Please enter the number you want to guess (1-100):
you guessed. Number 50 guess small
Please enter the number you want to guess (1-100):
$
The number you guessed is 75.
Please enter the number you want to guess (1-100):
"The number 60 you guessed is small." Please enter the number you want to guess (1-100 ):
The number you guessed is 65.
Please enter the number you want to guess (1-100):
The number 63 you guess is big
Please enter the number you want to guess (1-100): "
" You guess the number 62 guess big br> Please enter the number you want to guess (1-100):
Congratulations, you guessed it.