Chapter Three

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What will be displayed by this command: System.out.println(Math.pow(3, 3-1))

9

Which properties are true of String objects?

A) Their lengths never change B) The shortest string has zero length E) Only A and B are true

Java.text's NumberFormat class includes methods that

A) allow you to format currency B) allow you to format percentages C) round their display during the formatting process E) A, B, C, but not D

The advantages of the DecimalFormat class compared with the NumberFormat class include

A) precise control over the number of digits to be displayed B) control over the presence of a leading zero E) only A and B

If two variables contain aliases of the same object then

A) the object may be modified using either alias D) the object will become an "orphan" if both variables are set to null E) answers A and D are correct

The advantage(s) of the Random class' pseudo-random number generators compared to the Math.random method is that

A) you may create several random number generators C) you can initialize and reinitialize Random generators D) you can generate random ints, floats, and ints within a range E) all but answer B

What happens if you attempt to use a variable before it has been initialized?

Answers A and B are correct

What is the function of the dot operator?

Both B and C are correct

For the program to get a name interactively a Scanner object must be instantiated. Write the Java statement to do this

Scanner scan = new Scanner(System.in)

Say you write a program that makes use of the Random class

The program won't compile-you'll receive a syntax error about the missing class.

In Java a variable may contain

a value or a reference

An API is

an Application Programming Interface

In Java "instantiation" means,

creating a new object of the class

Write a statement using a method to guarantee that the initial will be a capital letter

firstInitial = firstInitial.toUpperCase( )

Write a method to extract the initial from the first name

firstInitial = firstName.substring(0,1)

Write a statement using a Scanner method to get the first name interactively

firstNam = scan.nextLine( )

Which of the following will yield a pseudorandom number in the range [ -5 +5 ) given the following: Random gen = new Random( )

gen.nextFloat( ) * 10 - 5

Consider the following two lines of code. What can you say about s1 and s2? String s1 = "testing" + "123" String s2 = new String("testing 123")

s1 and s2 are both references to different String objects

Given the following code fragment String strA = "aBcDeFg" String strB = strA.toLowerCase( ) strB = strB.toUpperCase( ) String strC = strA.toUpperCase( )

strB.compareTo(strC) would yield 0

An "alias" is when

two different reference variables refer to the same physical object

The String class' compareTo method

yields 0 if the two strings are identical


Set pelajaran terkait

MISY 4350 Ch. 2, MISY 4350 Ch. 4, MISY 4350 Ch. 5, MISY 4350 Ch. 6, MISY 4350 Ch. 3

View Set

Chapter 6 Econ Assignment Answers

View Set

Mastering A & P Chapter 1, Chapter 15 A&P Mastering, Chapter 15 Mastering A and P, Chapter 14 (Mastering A&P), Chapter 14 Mastering A&P, Mastering A&P Chapter 12, Mastering A&P chapter 12, chapter 11 mastering a and p, chapter 10 (mastering a&p), Mas...

View Set

Business Management 2019 Exam Bible

View Set

PrepU Ch 26 Management of Pts with Dysrhythmias & Conduction Problems

View Set

Chapter 9: Managing Conflict in Relationships

View Set