Structure of the Problem Requirements
In this problem we will learn how to generate random numbers in Java Program. Before this we uploaded a program how to generate random numbers in C++ program. In java we use math class's methods and with little bit overriding it we can generate random numbers. There are two parameters in method one is starting point from where the random numbers will start generating and a range of last position(ending point).In this program we specified the range between 10 to 100. Here is the source code of this problem which help you in better understanding.
Source Code
public static int generate(int min,int max)
{
return min + (int)(Math.random() * ((max - min) + 1));
}
public static void main(String[] args)
{
System.out.println("\t \t \t LEP Tutorials \n ");
for (int i =0;i<5;i++)
{
System.out.println("Random Numbers Generator :" + generate(10,100));
}
}
}
Output of the Program
Generate Random Number in Java |
Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.
0 comments:
Post a Comment