-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomClassIn.java
More file actions
32 lines (23 loc) · 1.03 KB
/
RandomClassIn.java
File metadata and controls
32 lines (23 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// in java random is a class in the java.util package.
// it is used to generate pseudo random numbers of diffrent types
// such as int , float , double , long and float
// it allows generating random numbers within a specified range
// last number is exculsive
// (1 - 11) --> will generate numbers between 1 to 10.
import java.util.Random ; // importing the random class
// the methods in random class is non static so you need to create
//object of it to use the methods of random class
//***************** ALSO LOOK FOR MathClassIn.java
public class RandomClassIn {
public static void main(String[] args) {
Random random = new Random(); // creating the random class object
// it is not mandatory pass the starting range
// ending range will be exluded
// 1.
int num = random.nextInt(3);
System.out.println(num); // printing a random number (exlusive - 3)
// 2.
boolean Value = random.nextBoolean();//will print true or false
System.out.println(Value); // will print true or false only
}
}