JAVA random number,
In JAVAZ, the random number code is
Math. random ().
Next I will write a random number:
Package random; public class random {public static void main (String [] args) {// TODO Auto-generated method stubint result = (int) (Math. random () * 100) + 1; // This is 1 ~ Random Number between 100: System. out. println (result );}}
Running result:
Through the random number, you can also do some simple operations, such as a small game Interaction:
Package random; import java. util. usage; public class random {public static void main (String [] args) {// TODO Auto-generated method stubScanner s = new usage (System. in); int result = (int) (Math. random () * 100) + 1; System. out. println ("guess the digit ratio"); System. out. println ("enter a number from 1 to 100 to see if it is the same as our random number:"); while (true) {int guessnume = s. nextInt (); if (guessnume> result) {System. out. println ("the number you guessed is too large");} else if (guessnume <result ) {System. out. println ("the number you guessed is a little small");} else {System. out. println ("Congratulations, you guessed it. "); Break ;}}}}
Running result: