Number of game guesses

Source: Internet
Author: User

Number of game guesses

Import java. util. collections;

 

Public class GuessNum {

Public static void main (String [] args ){
Second s = new second (System. in); // accept the input (number of guesses)
Int user = 0; // number of user inputs (small)
Int user2 = 100; // number of user inputs (large)
Int no =-1; // The number of input records.

/* Generate a random number and give it to the user */
Double d = Math. random ();
Int guess = (int) (d * 100)/1;

/* Compare the number of user guesses with the number generated */
For (; no! = Guess ;){
System. out. println ("please input a number in" + user + "to" + user2 + "! ");
System. out. print ("please input a number which you guess :");
No = s. nextInt ();
If (no> guess ){
System. out. println ("too big! ");
User2 = no;
}
If (no <guess ){
System. out. println ("too small! ");
User = no;
}
}
System. out. println ("congratulation! ");

}

}

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.