- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
Mathematical Library Methods
Chapter 7
Mathematical Library Methods
Class 10 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Program: Generate Random Integers in Given Ranges
11. Write a program to generate random integers in the following ranges:
i. 10 to 20 (both inclusive)
ii. 25 to 50 (both inclusive)
import java.util.Scanner;
public class RandomNumberRange {
public static void main(String[] args) {
// Random number between 10 and 20 (inclusive)
int r1 = (int)(Math.random() * (20 - 10 + 1)) + 10;
// Random number between 25 and 50 (inclusive)
int r2 = (int)(Math.random() * (50 - 25 + 1)) + 25;
// Output
System.out.println("Random number between 10 and 20: " + r1);
System.out.println("Random number between 25 and 50: " + r2);
}
}
Output
Sample Output Random number between 10 and 20: 17 Random number between 25 and 50: 43
Explanation
Formula Used
Random Integer = (int) (Math.random() × (max - min + 1)) + min- Math.random() generates a value between 0.0 and 0.999...
- Multiplying by (max - min + 1) sets the range size
- Adding min shifts the range to the required starting value
- Type casting to int removes the decimal part
