Math class of javautil package can be used to generate random number this method returns double type random numbers in the range 00 included to 10 not included. For Example in order to generate a random number between 10 and 20 set the maxvalue as 20 and minvalue as 10. Random random new Random seed.
Example int randomNum intMathrandom 101.
Scanner class and its function nextInt is used to obtain the input and println function is used to print on the screen. Following is the block. For int i 0. We can also use the following formula if we want to a generate random number between a specified range.