100+ tutorials, source code, and examples to help you develop creative and technical skills.

Java Program to generate Random Number between two numbers using Random class

RandomNumber2.java

import java.util.*; 

/* Code From Learnoset - Learn Coding Online.
    Download Learnoset App from PlayStore to learn coding,
    projects, algorithms, error handling
 */

// Java Program to generate Random Number between two numbers using Random class

public class RandomNumber2 {
    
	public static void main(String args[]) {
       
	   // create Scanner class object to get input from user
        Scanner scanner = new Scanner(System.in);
		
        System.out.println("Enter minimum value");
		
        //get user's enetered value from 'scanner' object into 'minimum' variable
        int minimum = scanner.nextInt();
		
		System.out.println("Enter minimum value");
		
		//get user's enetered value from 'scanner' object into 'maximum' variable
        int maximum = scanner.nextInt();
		
		// create Random class object
		Random randomObj = new Random();
		
		/* generate random number using 'nextInt(int)' function of Random class
		   this function take 1 argument
		   first argument is a bound (max value)*/
		int randomNumber = randomObj.nextInt(maximum - minimum) + minimum;
		
		System.out.println("Generated random number is = "+randomNumber);
	
    }
}

Projects with Source Code + Video Tutorials

You can download our Java and Android Studio Projects with Source Code and Video Tutorials.

Custom-Navigation-bar-with-Material-UI-design
Custom Navigation bar with Material UI design
Gamer-Bazi---Tournament-Application-with-Admob-Ads-&-Web-Admin-Panel
Gamer Bazi - Tournament Application with Admob Ads & Web Admin Panel
How-to-create-Modern-Login-and-Register-screen-in-Android-Studio-|-Material-UI-Design-|-Part---06
How to create Modern Login and Register screen in Android Studio | Material UI Design | Part - 06

If you have any Questions or Queries
You can mail us at info.learnoset@gmail.com

Follow us to learn Coding and get in touch with new Technologies.