In this example we will show how to generate a random number using random method in Java.
Source Code
package com.beginner.examples;
public class RandomExample {
public static void main(String[] args) {
//generate a random number
int rand = (int)(Math.random()* 10 );
System.out.println(rand);
}
}
Output:
9