Chapter 4

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is the value of the following expression? 1 % 12 A. This is an error because 12 is greater than 1 B. 0 C. 1 D. -11

1

What does the following statement sequence print if the user input is 123? Scanner in = new Scanner(System.in); System.out.print("Enter a number: "); String str = in.next(); str += 456; System.out.println(str); A. 123456 B. Compile-time error C. Run-time error D. 579

123456

What is the value of Math.abs(-2)? A. 2 B. 0 C. 4 D. -2

2

The first step in problem solving is A. To understand the problem and its inputs and outputs B. To write the expression that calculates the answer C. To do examples by hand that confirm the solution will work D. To write Java code that can be executed and tested

To understand the problem and its inputs and outputs

Which of the following options defines an integer variable? A. integer age; B. age: int; C. char age; D. int age;

int age;

Which one of the following operators computes the remainder of an integer division? A. \ B. / C. ! D. %

%

Which is a correct representation of the given mathematical expression in Java? a + b _____ 2 A. a + (b / 2) B. a + b / 2 C. a + b % 2 D. (a + b) / 2

(a + b) / 2

What is the value of the following expression? 2 + 3 + 5 / 2 A. 7.5 B. 6 C. 7 D. 5

7

What is the output of the following code snippet? int value = 3; value++; System.out.println(value); A. No output due to syntax error B. 3 C. 4 D. 2

4

What is the result of the following code snippet? double bottles; double bottleVolume = bottles * 2; System.out.println(bottleVolume) A. Does not compile B. 0 C. 2 D. 1

Does not compile

Which statements about numeric types in Java are true? I.There is more than one integer type II.The data type float uses twice the storage of double III.The numeric range of the Java integer type is related to powers of two A. II, III B. I, III C. I, II D. I, II, III

I, III

Which of the following statements about constants in Java are true? I.Although not required, constants are commonly named using uppercase letters II.Only integer values can appear as constants III.A variable can be defined with an initial value, but the reserved word final prevents it from being changed IV.A named constant makes computations that use it clearer A. I, II, III B. II, III, IV C. I, II, IV D. I, III, IV

I, III, IV

Which of the following statements with comments is(are) valid? I. int cnt = 0; /* Set count to 0 II. int cnt = 0; /* Set count to 0 */ III. int cnt = 0; // Set count to 0 A. I and II B. Only I C. Only III D. II and III

II and III

What is wrong with the following code? int count = 2000 * 3000 * 4000; A. Illegal expression B. Wrong data type C. Variable is undefined D. Integer overflow

Integer overflow

Which one of the following refers to a number constant that appears in code without explanation? A. String literal B. Constant C. Magic number D. Variable

Magic number

One way to avoid round-off errors is to use: A. Math.sqrt() B. Math.pow() C. Math.truncate() D. Math.round()

Math.round()

The typical ranges for integers may seem strange but are derived from A. Overflows B. Powers of two because of base 2 representation within the computer C. Field requirements for typical usage and limits D. Base 10 floating-point precision

Powers of two because of base 2 representation within the computer

What is the result of the following statement? String s = "You" + "had" + "me" + "at" + "hello"; A. The string s has the following value: "You had me at "hello" B. The statement results in an error because the + operator can be used only with numbers C. The string s has the following value: "Youhadmeathello" D. The statement results in an error because the + operation cannot be performed on string literals

The string s has the following value: "Youhadmeathello"

Which one of the following statements displays the output as 54321.00? A. System.out.printf("%8.2f", 54321.0); B. System.out.printf("%8,2f", 54321.0); C. System.out.printf("%8.00f", 54321.0); D. System.out.printf(",8.2f", 54321.0);

System.out.printf("%8.2f", 54321.0);

What is wrong with the following code snippet? int width = 10; height = 20.00; System.out.println("area = " + (width * height)); A. The code snippet attempts to add a number to a string variable. B. The code snippet attempts to assign a decimal value to an integer variable. C. The code snippet uses an uninitialized variable. D. The code snippet uses an undeclared variable.

The code snippet uses an undeclared variable.

Which one of the following statements can be used to get the fifth character from a string str? A. char c = str[4]; B. char c = str.charAt(4); C. char c = str.charAt(5); D. char c = str[5];

char c = str.charAt(4);

Assume the variable str has been declared to be a String that has at least one character. Which is the following represents the last character in str? A. str.charAt(str.length() - 1) B. str.lastChar() C. str.substring(str.length()) D. str.charAt(str.length())

str.charAt(str.length() - 1)

How do you extract the first 5 characters from the string str? A. str.substring(0,5) B. str.substring(5) C. substring(str, 5) D. substring.str(0,5)

str.substring(0,5)


Conjuntos de estudio relacionados

Economics Chapter 10 Lesson 1-3 and Chapter 11 Lesson 1 Study Guide

View Set

Davis CH 30: Disorders of the Large Intestine

View Set

Research Methods in Psychology Chapter 1

View Set

Chapter 5 - Chapter 9 Supply Chain

View Set