Ch 3 MC compsci
What will be displayed by this command: System.out.println(Math.pow(3, 3-1));
9
What happens if you attempt to use a variable before it has been initialized?
A syntax error may be generated by the compiler A runtime error may occur during execution
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 D) truncate their display during the formatting process E) A, B, C, but not D
E) A, B, C, but not D
The advantage(s) of the Random class' pseudo-random number generators, compared to the Math.random method, is that A) you can generate random ints, floats, and ints within a range B) the generators in Random are more efficient than the one in Math.random C) you may create several random number generators D) you can initialize and reinitialize Random generators E) all but answer B
E) all but answer B
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 C) the ability to truncate values rather than to round them D) the ability to display a % automatically at the beginning of the display E) only A and B
E) only A and B
What is the function of the dot operator?
It allows one to access the data within an object when given a reference to the object It allows one to invoke a method within an object when given a reference to the object
Say you write a program that makes use of the Random class, but you fail to include an import statement for java.util.Random (or java.util.*). What will happen when you attempt to compile and run your program.
The program won't compile-you'll receive a syntax error about the missing class.
Which properties are true of String objects?
Their lengths never change The shortest string has zero length
In the StringMutation program shown in Listing 3.1, if phrase is initialized to "Einstein" what will Mutation #3 yield if Mutation #1: mutation1 = phrase.concat(".")?
XINSTXIN
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
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
If two variables contain aliases of the same object then
the object may be modified using either alias the object will become an "orphan" if both variables are set to null
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