the random class Flashcards
- Which class is used to generate random number?
a) java.lang.Object
b) java.util.randomNumber
c) java.util.Random
d) java.util.Object
c
- Which method is used to generate boolean random values in java?
a) nextBoolean()
b) randomBoolean()
c) previousBoolean()
d) generateBoolean()
a
- What is the return type of Math.random() method?
a) Integer
b) Double
c) String
d) Boolean
b
Random is a final class?
a) True
b) False
b Explanation: Random is not a final class and can be extended to implement the algorithm as per requirement.
What is the range of numbers returned by Math.random() method?
a) -1.0 to 1.0
b) -1 to 1
c) 0 to 100
d) 0.0 to 1.0
d
How many bits are used for generating random numbers?
a) 32
b) 64
c) 48
d) 8
c
What will be the output of the following Java code snippet?
int a = random.nextInt(15) + 1;
a) Random number between 1 to 15, including 1 and 15
b) Random number between 1 to 15, excluding 15
c) Random number between 1 to 15, excluding 1
d) Random number between 1 to 15, excluding 1 and 15
a
What will be the output of the following Java code snippet?
int a = random.nextInt(7) + 4;
a) Random number between 4 to 7, including 4 and 7
b) Random number between 4 to 7, excluding 4 and 7
c) Random number between 4 to 10, excluding 4 and 10
d) Random number between 4 to 10, including 4 and 10
d