## JAVA EXAMPLE PROGRAMS

Publish Your Article Here

# Program: How to generate random numbers in the given range?

 Description: Incase if we want to generate random number in the given range, then we need to use nextInt(limit) method. Here we need to pass the range limit. For example in the below example we are passing 50 as limit, so that the generated random number is always less than 50.

 Code: ```package com.java2novice.random; import java.util.Random; public class MyRandomInRange { public static void main(String a[]){ Random rnd = new Random(); System.out.println("Random Integers below 50:"); System.out.println(rnd.nextInt(50)); System.out.println(rnd.nextInt(50)); System.out.println(rnd.nextInt(50)); System.out.println(rnd.nextInt(50)); System.out.println(rnd.nextInt(50)); System.out.println(rnd.nextInt(50)); System.out.println(rnd.nextInt(50)); System.out.println(rnd.nextInt(50)); System.out.println(rnd.nextInt(50)); System.out.println(rnd.nextInt(50)); System.out.println(rnd.nextInt(50)); System.out.println(rnd.nextInt(50)); } } ```

 Output: ```Random Integers below 50: 28 41 23 28 5 14 3 32 29 12 32 7 ```

#### List of Random class sample programs:

Java2Novice - YouTube Channel
Knowledge Centre
What is abstract class or abstract method?
We cannot create instance for an abstract class. We can able to create instance for its subclass only. By specifying abstract keyword just before class, we can make a class as abstract class.

public abstract class MyAbstractClass{

}

Abstract class may or may not contains abstract methods. Abstract method is just method signature, it does not containes any implementation. Its subclass must provide implementation for abstract methods. Abstract methods are looks like as given below:

public abstract int getLength();
Famous Quotations
Millions long for immortality who do not know what to do with themselves on a rainy Sunday afternoon.
-- Susan Erz

### Other Interesting Sites

 Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle. Privacy Policy | Copyright © 2022 by Nataraja Gootooru. All Rights Reserved.