1 Import Java. Text. simpledateformat; 2 Import Java. util. date; 3 Import Java. util. vendor; 4 5 // Main Function 6 Public Class Calssone { 7 8 Public Static Void Main (string [] ARGs ){ 9 10 // Shit + Ctrl + O 11 Int Result; 12 // Generate a random number of less than 100 13 Int Number = ( Int ) (Math. Random () * 100 ); 14 System. Out. println ("\ n ************* do you have to hold the game? *********" ); 15 System. Out. println ("\ n ********* Random Number Generation: Don't tell you! * ******** \ N" ); 16 System. out. println ("\ n ************* answer: "+ number +" **************** \ n" ); 17 System. Out. println ("Let's use our brains to guess. Tips: He is an integer from 1 to 100" ); 18 Long Starttime = system. currenttimemillis (); // Define a time variable 19 For ( Int I = 1; I <100; I ++ ){ 20 System. Out. println ("Enter your second guess" + I +" ); 21 Result = calssone. Guess (I ); // Obtain the input result by calling the input function. 22 // Compare the output Console 23 If (Result> Number) 24 System. Out. println ("sorry, the number you guessed is greater than the number you guessed! " ); 25 Else If (Result < Number) 26 System. Out. println ("sorry, the number you guessed is smaller than the number you guessed! " ); 27 Else { 28 Simpledateformat snowdate = New Simpledateformat ("yyyy-mm-dd hh: mm: SS" ); 29 Long Sendtime = System. currenttimemillis (); 30 System. out. println ("\ n ************ correct answer: "+ number +" **************** \ n" ); 31 If (I = 1 ){ 32 System. Out. println ("Perfect !! Congratulations! In the middle !! " ); 33 } 34 Else If (I <10 ){ 35 System. Out. println ("Good job! You guessed a total of "+ I +" times and continue to cheer !! " ); 36 } 37 Else { 38 System. Out. println ("not bad! You guessed "+ I +" times in total. It's a long way to go! " ); 39 } 40 System. Out. println ("current time:" + snowdate. Format ( New Date ())); // New Date () is used to obtain the current system time 41 // System. Out. println ("current time:" + snowdate ); 42 System. Out. println ("time used:" + (sendtime-starttime)/1000 + "seconds" ); 43 Return ; 44 } 45 } 46 } 47 // Input Function 48 Public Static Int Guess ( Int I ){ 49 // Import java. util. Collections class package 50 Required SC = New Using (system. In ); 51 Int Result; 52 Try { 53 // Make the content entered on the console a number 54 Result = SC. nextint (); 55 Return Result; 56 } 57 Catch (Exception e ){ 58 // Todo: handle exception 59 System. Out. println ("You entered a number instead of a number. Please enter the number" + I + "again" ); 60 // Call this function to re-enter 61 Guess (I ); 62 } 63 Return 0 ; 64 } 65 }