import java.util.*;
class GenerateRandomNumber
{
public static void main(String args[])
{
int i=0;
Random r=new Random();
Scanner sc=new Scanner(System.in);
System.out.println("How many random numbers ,do you want to generate?");
int value=sc.nextInt();
System.out.println();
System.out.println("Generating Numbers");
for(i=0;i<value;i++)
{
int n=r.nextInt(6) + 1;
System.out.println(n);
}
}
}
/*In the loop it is written:
int n=r.nextInt(6) + 1;
Here 6 inside the parentesis is the maximum value of random number,since here we are considering a dice so I have set that to 6. And the +1 indicates the minimum possible number generated.You have to include
import java.util.*; library to use Random(). */
Comments
Post a Comment