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.
Import java. util. Random;
Import java. util. collections;
Public class caidx
{
Public static void main (String [] args)
{
Random r = new Random ();
Int dianshu = r. nextInt (6 );
Dianshu ++;
System. out. println ("==== guess the size of the game ==== ");
S = new partition (System. in );
System. out. println ("enter" large "or" small "");
String daxiao = s. next ();
If (dianshu <= 3 & daxiao. equals ("small") {System. out. println ("the number of points is" + dianshu + ". You guessed "+ daxiao + ". Congratulations! You guessed it! ");}
If (dianshu <= 3 & daxiao. equals ("") {System. out. println ("the number of points is" + dianshu + ". You guessed "+ daxiao + ". Sorry, I guess it is wrong. ");}
If (dianshu> 3 & daxiao. equals ("big") {System. out. println ("the number of points is" + dianshu + ". You guessed "+ daxiao + ". Congratulations! You guessed it! ");}
If (dianshu> 3 & daxiao. equals ("small") {System. out. println ("the number of points is" + dianshu + ". You guessed "+ daxiao + ". Sorry, I guess it is wrong. ");}
If (! (Daxiao. equals ("big") | daxiao. equals ("small") {System. out. println ("only" large "or" small "can be entered "");}
}
}
======================================
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>