Java Random Number Generation Quiz

Java Random Number Generation Quiz

12th Grade

10 Qs

quiz-placeholder

Similar activities

Большое Повторение C#

Большое Повторение C#

5th Grade - University

15 Qs

AP CS practice 2

AP CS practice 2

11th Grade - University

12 Qs

Javascript Basics Quiz Review

Javascript Basics Quiz Review

12th Grade

15 Qs

Determinoismo, casualità, caos

Determinoismo, casualità, caos

12th Grade

11 Qs

Variables and Data Types

Variables and Data Types

10th - 12th Grade

10 Qs

Python - тест

Python - тест

1st - 12th Grade

15 Qs

Arrays Unit

Arrays Unit

10th - 12th Grade

15 Qs

Random Number Generation in Java

Random Number Generation in Java

12th Grade

13 Qs

Java Random Number Generation Quiz

Java Random Number Generation Quiz

Assessment

Quiz

Computers

12th Grade

Hard

Created by

Patrick Bryar

FREE Resource

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);

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?