Java program, guess the size of the game

Source: Internet
Author: User

Java program, guess the size of the game

A dice usually has 6 points, including 1, 2, 3, 4, 5, and 6. We remember 1, 2, and 3 as "small", and 4, 5, and 6 as "big ". "Guessed" is displayed on the page, and "guessed wrong" is recorded as "guessed wrong. This program can be implemented in Java.

 
  1. Import java. util. Random;

  2. Import java. util. collections;

  3. Public class caidx

  4. {

  5. Public static void main (String [] args)

  6. {

  7. Random r = new Random ();

  8. Int dianshu = r. nextInt (6 );

  9. Dianshu ++;

  10. System. out. println ("==== guess the size of the game ==== ");

  11. S = new partition (System. in );

  12. System. out. println ("enter" large "or" small "");

  13. String daxiao = s. next ();

  14. If (dianshu <= 3 & daxiao. equals ("small") {System. out. println ("the number of points is" + dianshu + ". You guessed "+ daxiao + ". Congratulations! You guessed it! ");}

  15. If (dianshu <= 3 & daxiao. equals ("") {System. out. println ("the number of points is" + dianshu + ". You guessed "+ daxiao + ". Sorry, I guess it is wrong. ");}

  16. If (dianshu> 3 & daxiao. equals ("big") {System. out. println ("the number of points is" + dianshu + ". You guessed "+ daxiao + ". Congratulations! You guessed it! ");}

  17. If (dianshu> 3 & daxiao. equals ("small") {System. out. println ("the number of points is" + dianshu + ". You guessed "+ daxiao + ". Sorry, I guess it is wrong. ");}

  18. If (! (Daxiao. equals ("big") | daxiao. equals ("small") {System. out. println ("only" large "or" small "can be entered "");}

  19. }

  20. }

======================================

Below is the doscommand

C: \ Documents ents and Settings \ Administrator> d:

D: \> cd javacx

D: \ javacx> java caidx
==== Guess the size of the game ====
Enter "big" or "small"
Large
The number of points is 2. You guess it's big. Sorry, I guess it is wrong.

D: \ javacx> java caidx
==== Guess the size of the game ====
Enter "big" or "small"
Large
The number of points is 6. You guess it's big. Congratulations! You guessed it!

D: \ javacx> java caidx
==== Guess the size of the game ====
Enter "big" or "small"
Small
The number of points is 1. You guessed it was small. Congratulations! You guessed it!

D: \ javacx> java caidx
==== Guess the size of the game ====
Enter "big" or "small"
Small
The number of points is 2. You guessed it was small. Congratulations! You guessed it!

D: \ javacx> java caidx
==== Guess the size of the game ====
Enter "big" or "small"
Small
The number of points is 4. You guessed it was small. Sorry, I guess it is wrong.

D: \ javacx> java caidx
==== Guess the size of the game ====
Enter "big" or "small"
Hi!
You can only enter "large" or "small"

D: \ javacx>

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.