Thursday, January 12, 2017

Program to generate 6 digits Random Number(Positive Only).

import java.util.*;
class RandomNum
{
public static void main(String...args)
{
//Random object created.
Random rn=new Random();

//Random method called for integer values with fixed value.
int num=rn.nextInt(1000000);

//show Random with 6 digits number.
if(num>100000)
{
System.out.println("Your Random No. is : "+num);
}
else
{
System.out.println("Retry!");
}

}
}

                                                                                                                                   

Output:


No comments:

Post a Comment