Generating a Random Number in java is pretty easy by using Random() method in java. by using it we can create a simple dice game
Program:
Output: it will randomly changed when ever you run this program from 1 to 6
Program:
import java.util.*;
class apple
{
public static void main(String[] args)
{
Random dice = new Random();
int roll;
for (int j = 1; j <= 1; j++)
{
roll = 1 + dice.nextInt(6);
System.out.println(roll + "");
}
}
}
Output: it will randomly changed when ever you run this program from 1 to 6