
generate random number + java
Quiz
ā¢
Computers
ā¢
Professional Development
ā¢
Practice Problem
ā¢
Hard
ANIL KUMAR
FREE Resource
Enhance your content in a minute
72 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
20 sec ⢠1 pt
What is the code in the image?
Answer explanation
The answer is (C). The code in the image is for a Java program that uses a random number generator to generate numbers between 1 and 6. The main method of the program first creates a random number generator object, and then loops 10 times. In each iteration of the loop, the program generates a random number and prints it to the console.
2.
MULTIPLE CHOICE QUESTION
20 sec ⢠1 pt
What is the line of code that generates a random number between 1 and 100?
Answer explanation
The answer is (C). The line of code int answer = rand.nextInt(MAX); generates a random number between 1 and 100, where rand is an object of the Random class and MAX is a constant with the value of 100.
3.
MULTIPLE CHOICE QUESTION
20 sec ⢠1 pt
What is the purpose of the setSeed() method in the code in the image?
Answer explanation
The answer is (B). The setSeed() method in the code in the image is used to set the seed for the random number generator. The seed is a number that is used to initialize the random number generator, and it affects the sequence of random numbers that are generated. By setting the seed, the program can be guaranteed to generate the same random numbers each time it is run.
4.
MULTIPLE CHOICE QUESTION
20 sec ⢠1 pt
What is the range of random numbers generated by the code in the image?
Answer explanation
The answer is (A). The code in the image uses the nextInt() method of the Random class to generate random numbers. The nextInt() method generates a random number between 0 and the specified upper bound, which in this case is 50. Therefore, the range of random numbers generated by the code in the image is 0 to 49.
5.
MULTIPLE CHOICE QUESTION
20 sec ⢠1 pt
What is the name of the class that contains the code in the image?
Answer explanation
The answer is (A). The code in the image is contained in the RandomNumbersDemo class. The RandomNumbersDemo class is declared on line 1 of the image.
6.
MULTIPLE CHOICE QUESTION
20 sec ⢠1 pt
What is the value of the variable randomnum after the code in the image is executed?
Answer explanation
The answer is (A). The value of the variable randomnum after the code in the image is executed is 0.09112701489411879. This is because the code in the image uses the nextDouble() method of the Random class to generate a random double number between 0.0 and 1.0. The value of randomnum will be different each time the code is executed.
7.
MULTIPLE CHOICE QUESTION
20 sec ⢠1 pt
What is the purpose of the randomNum() method in the image?
Answer explanation
The answer is (A). The purpose of the randomNum() method in the image is to generate a random number between 188 and 2008, inclusive. The method first creates a random number generator object, and then uses the nextInt() method to generate a random number between 0 and 2008, inclusive. The method then adds 188 to the result of the nextInt() method to ensure that the random number is between 188 and 2008, inclusive.
Create a free account and access millions of resources
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
69 questions
FC0-U61(758) Quiz 4
Quiz
ā¢
Professional Development
75 questions
Generative AI MCQ Quiz
Quiz
ā¢
Professional Development
73 questions
AWS Certified Cloud Practitioner Exam Practice Questions
Quiz
ā¢
Professional Development
67 questions
NetApp Technology Solutions
Quiz
ā¢
Professional Development
76 questions
eval2-ok
Quiz
ā¢
Professional Development
70 questions
DCF I SEM MCQ Test 2024
Quiz
ā¢
Professional Development
67 questions
Quiz sobre PL/SQL
Quiz
ā¢
Professional Development
Popular Resources on Wayground
5 questions
This is not a...winter edition (Drawing game)
Quiz
ā¢
1st - 5th Grade
25 questions
Multiplication Facts
Quiz
ā¢
5th Grade
10 questions
Identify Iconic Christmas Movie Scenes
Interactive video
ā¢
6th - 10th Grade
20 questions
Christmas Trivia
Quiz
ā¢
6th - 8th Grade
18 questions
Kids Christmas Trivia
Quiz
ā¢
KG - 5th Grade
11 questions
How well do you know your Christmas Characters?
Lesson
ā¢
3rd Grade
14 questions
Christmas Trivia
Quiz
ā¢
5th Grade
20 questions
How the Grinch Stole Christmas
Quiz
ā¢
5th Grade
Discover more resources for Computers
26 questions
Christmas Movie Trivia
Lesson
ā¢
8th Grade - Professio...
25 questions
Christmas Movies
Quiz
ā¢
Professional Development
20 questions
Christmas Trivia
Quiz
ā¢
Professional Development
15 questions
Fun Holiday Trivia
Quiz
ā¢
Professional Development
25 questions
Name That Tune - Christmas
Quiz
ā¢
Professional Development
29 questions
Christmas Song Emoji Pictionary
Quiz
ā¢
Professional Development
9 questions
Holiday Movie Trivia
Lesson
ā¢
Professional Development
34 questions
Winter Trivia
Quiz
ā¢
Professional Development
