the random class Flashcards

1
Q
  1. Which class is used to generate random number?
    a) java.lang.Object
    b) java.util.randomNumber
    c) java.util.Random
    d) java.util.Object
A

c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. Which method is used to generate boolean random values in java?
    a) nextBoolean()
    b) randomBoolean()
    c) previousBoolean()
    d) generateBoolean()
A

a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. What is the return type of Math.random() method?
    a) Integer
    b) Double
    c) String
    d) Boolean
A

b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Random is a final class?

a) True
b) False

A
b
Explanation: Random is not a final class and can be extended to implement the algorithm as per requirement.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How many bits are used for generating random numbers?

a) 32
b) 64
c) 48
d) 8

A

c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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

A

d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly