Search Header Logo

Java Random Number Generation Quiz

Authored by Patrick Bryar

Computers

12th Grade

Java Random Number Generation Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What method is used in Java to generate a random number between 0.0 (inclusive) and 1.0 (exclusive)?

Math.randomInt()

Random.nextInt()

Random.generate()

Math.random()

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following formulas can be used to generate a random integer between 0 and 100 in Java?

int randomNum = (int)(Math.random() * 101);

int randomNum = (int)(Math.random() * 100);

int randomNum = Math.random() * 100;

int randomNum = Random.nextInt(100);

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the return type of the Math.random() method in Java?

int

double

float

long

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the range of values returned by Math.random() in Java?

0.0 (inclusive) to 1.0 (exclusive)

0.0 (exclusive) to 1.0 (exclusive)

0.0 (inclusive) to 1.0 (inclusive)

0.0 (exclusive) to 1.0 (inclusive)

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

To generate a random integer between 1 and 10, which of the following expressions is correct?

int randomNum = (int)(Math.random() * 10) + 1;

int randomNum = Math.random() * 10 + 1;

int randomNum = (int)(Math.random() * 11);

int randomNum = Random.nextInt(10) + 1;

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the purpose of casting in the expression (int)(Math.random() * 101)?

To generate a floating-point number

To ensure the result is always positive

To increase the range of random numbers

To convert the double result to an integer

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is a correct way to generate a random number between 0 and 50?

int randomNum = (int)(Math.random() * 50);

int randomNum = Math.random() * 50;

int randomNum = (int)(Math.random() * 51);

int randomNum = Random.nextInt(50);

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?