Guess the word little game

Source: Internet
Author: User
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.

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.