Unit 6 Test Answers because I'm a ƒaguette

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

The Math.random method generates a random number x, such that

0 <= x < 1

Examples of class methods are

Math methods.

The methods in the Bank class are

object methods.

Access to methods of the Bank class requires

the creation of one or more Bank objects.

Class methods tend to be used for

utility classes.

What is the output of the following program? import java.util.Random; public class Question33 { public static void main(String args[ ]) { Random rand = new Random(); rand.setSeed(100); System.out.println(rand.nextInt(900) + 100); System.out.println(rand.nextInt(900) + 100); System.out.println(rand.nextInt(900) + 100); System.out.println(rand.nextInt(900) + 100); System.out.println(rand.nextInt(900) + 100); System.out.println(rand.nextInt(900) + 100); System.out.println(rand.nextInt(900) + 100); System.out.println(rand.nextInt(900) + 100); System.out.println(rand.nextInt(900) + 100); System.out.println(rand.nextInt(900) + 100); } }

10 random integers in the [100..999] range

What is the output of the following program? import java.util.Random; public class Question34 { public static void main(String args[ ]) { Random rand = new Random(); rand.setSeed(100); System.out.println(rand.nextDouble()); System.out.println(rand.nextDouble()); System.out.println(rand.nextDouble()); System.out.println(rand.nextDouble()); System.out.println(rand.nextDouble()); } }

5 double numbers greater-or-equal to zero and less-than 1.

Consider the following program segment. for (int k = 1; k <= 10; k++) { double var1 = Math.random() * 100; int var2 = (int) var1 + 10; System.out.print(var2 + " "); } Which of the following are possible outputs of executing the program segment?

All of these.

Examples of object methods are

Bank, Random, and DecimalFormat.

Assume that rand is an object of the Random class. Which of the following statements controls the generation of the random numbers, such that each execution generates the same sequence of numbers?

Both rand.setSeed(3333); AND Random rand = new Random(3333);

drawPolygon & fillPolygon are both methods of the _______ class.

Graphics

Which of the following statements constructs an Integer object correctly?

Integer obj = new Integer(100);

By Java program writing convention, which of the following is true?

Object identifiers start with a lower-case letter and class identifiers start with a capital letter.

nextInt & nextDouble are both methods of which classes?

Random and Scanner

Which of the following ranges is generated by this statement: int number = (int) (Math.random() * 250 - 125); ?

[-125..124]

Consider the following program segment. for (int k = 1; k <= 10; k++) { double var1 = Math.random() * 100; int var2 = (int) var1 + 10; System.out.print(var2 + " "); } What is the range of possible random integers generated by the code above?

[10 . . . 109]

Which of the following ranges is generated by this statement: int number = (int) (Math.random() * 1201 + 400); ?

[400..1600]

Which of the following ranges is generated by this statement: int number = (int) (Math.random() * 72 + 57); ?

[57..128]

A class is __________ .

a data type

In the statement int temp = Integer.MAX_VALUE + 1; variable temp stores

a negative integer value.

An object is ______.

a variable.

An object method is called by using

an object identifier, followed by a period and the method identifier.

A feature in Java version 5.0 and later, which automatically handles wrapping, but is not used on the AP Computer Science Examination is called

auto-boxing.

Which of the following statements generates a random character in the ['A'..'Z'] range?

char letter = (char) (int) (Math.random() * 26 + 65);

The methods in the Math class are

class methods.

Integer.MAX_VALUE and Integer.MIN_VALUE are examples of

constant fields or attributes.

Consider the following statement: ______ is a computer science tool that involves using program features without knowledge of how the program features are implemented. This statement explains

information hiding.

Which of the following program segments generates a random integer in the range [1000 . . . 9999] ?

int hi = 9999; int lo = 1000; int range = hi - lo + 1; int randInt = (int) (Math.random() * range) + 1000;

Which of the following statements generates a random number in the [-41..101] range?

int number = (int) (Math.random() * 143 - 41;

Which of the following statements generates a random number in the [41..101] range?

int number = (int) (Math.random() * 61 + 41);

Which of the following statements generates a random number in the [-101..-41] range?

int number = (int) (Math.random() * 61 - 101);

Assume that rand is an object of the Random class. Which of the following statements generates a random number in the [1..1000] range?

int number = rand.nextInt(1000) + 1;

Assume that rand is an object of the Random class. Which of the following statements generates a random number in the [0..100] range?

int number = rand.nextInt(101);

Assume that rand is an object of the Random class. Which of the following statements generates a random number in the [200..600] range?

int number = rand.nextInt(401) + 200;

The Random class is found inside the __________ package.

java.util

The methods in the Random class are

object methods.

The Java keyword new is used to construct

objects only.

Assume that rand is an object of the Random class. Numbers generated by a call to Math.random() are in the same range as numbers called by

rand.nextDouble();

An object is a

single instance of a class.

A wrapper class creates objects capable of

storing primitive data values like int and double.

A class method is called by using

the class identifier, followed by a period and the method identifier.

The new Java keyword must be used with

the construction of each object.


संबंधित स्टडी सेट्स

Final Exam Cultural Anthropology

View Set

Health Portion Chapter 3 Disability Income Insurance

View Set

micro quiz 17, micro quiz 16, Quiz Chapter 15, quiz 13 micro , Micro quiz 14

View Set

theories of personality exam 2 (chapters 5,6,7,8)

View Set

Med-Surg Ch. 26 Cardiac Dysrhythmias

View Set

Andrew Carnegie, Philanthropist with exam review

View Set

Self-Test for Chapter 5 Humerus & Shoulder Girdle

View Set

Chapter 5 - Elasticity and Its Application

View Set

AP Human Geography-certain countries & capital cities of North Africa & Southwest/Central Asia

View Set

Hoyer - Chapter 8: Judgment and Decision Making Based on High Effort

View Set