Java Ch. 3 Quiz

Ace your homework & exams now with Quizwiz!

If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than str2? (1) (str1 < str2) (2) (str1.equals(str2) < 0) (3) (str1.compareTo(str2) < 0) a. 2 b. 3 c. 1, 2, and 3 will all work d. 2 and 3

3

What will be printed when the following code is executed? double x = 45678.259; System.out.printf("%,.2f", x); a. 45,678.3 b. 0,045,678.26 c. 45,678.26 d. 45678.259

45,678.26

If you prematurely terminate an if statement with a semicolon, the compiler will: a. Not display an error message b. Assume you are placing a null statement there c. All of these d. None of these

All of these

This is an international coding system that is extensive enough to represent all the characters of all the world's alphabets: a. ASCII b. Unicode c. Java d. None of these

Unicode

In Java, when a character is stored in memory, it is actually stored as a(n): a. ASCII character code b. EBCDIC character code c. Unicode number d. Morse code

Unicode number

What is the value of ans after the following code has been executed? int x = 35; int y = 20, ans = 80; if (x < y); ans += y; a. 100 b. 35 c. 55 d. 80

100

Enclosing a group of statements inside a set of braces creates a: a. block of statements b. boolean expression c. loop d. nothing, it is just for readability

block of statements

A Boolean expression is one that is either: a. true or false b. x or y c. Positive or negative d. None of these

true or false

To do a case insensitive compare which of the following could be used to test the equality of two strings, str1 and str2? a. (str1.equalsIgnoreCase(str2)) b. (str1.compareToIgnoreCase(str2) == 0) c. Only (str1.equalsIgnoreCase(str2)) d. (str1.equalsIgnoreCase(str2)) and (str1.compareToIgnoreCase(str2) == 0)

(str1.equalsIgnoreCase(str2)) and (str1.compareToIgnoreCase(str2) == 0)

What will be the value of ans after the following code has been executed? int ans = 10; int x = 65; int y = 55; if (x >= y) ans = x + y; a. 10 b. 120 c. 100 d. No value, there is a syntax error.

120

What is the value of x after the following code has been executed? int x = 75; int y = 90; if (x != y) x += y; a. 15 b. 90 c. 75 d. 165

165

What will be printed when the following code is executed? double x = 45678.259; String output = String.format("%,.1f", x); System.out.println(output); a. 45,678.259 b. 45,678.26 c. 45,678.3 d. 45678.259

45,678.3

What does the following code display? int d = 9, e = 12; System.out.printf("%d %d\n", d, e); a. %d 9 b. %9 %12 c. %d %d d. 9 12

9 12

This is a boolean variable that signals when some condition exists in the program: a. Case b. Flag c. Sentinel d. Block

Flag

This type of operator determines whether a specific relationship exists between two values: a. Mathematical b. Unary c. Logical d. Relational

Relational

In most editors, you are indenting by one level each time that you press this key: a. Tab b. Shift c. Alt d. Space

Tab

The expression tested by an if statement must evaluate to: a. +1 or -1 b. t or f c. 0 or 1 d. true or false

true or false

If chr is a character variable, which of the following if statements is written correctly? a. if (chr == "a") b. if (chr = 'a') c. if (chr == 'a') d. if (chr = "a")

if (chr == 'a')

A flag may have the values: a. +1 or -1 b. true or false c. of any character d. 0 or 1

true or false

What will be the value of bonus after the following code is executed? int bonus, sales = 10000; if (sales < 5000) bonus = 200; else if (sales <7500) bonus = 500; else if (sales < 10000) bonus = 750; else if (sales < 20000) bonus = 1000; else bonus = 1250; a. 200 b. 1250 c. 1000 d. 500 e. 750

1000

What does the following code display? double x = 12.3798146; System.out.printf("%.2f\n", x); a. 1238 b. 12.38 c. 123798146 d. %12.38

12.38

If str1 and str2 are both Strings, which of the following expressions will correctly determine whether they are equal? (1) (str1 == str2) (2) str1.equals(str2) (3) (str1.compareTo(str2) == 0) a. 1 and 3 b. 2 and 3 c. 1, 2, and 3 will all work d. 1 and 2

2 and 3

What will be the value of ans after the following code has been executed? int x = 90, y = 55, ans = 10; if ( x == y ); ans *= 2; a. 10 b. 145 c. 20 d. No value, there is a syntax error.

20

These operators use two operands: a. Unary b. Binary c. Tertiary d. None of these

Binary

The switch statement is a: a. Sequence structure b. Multiple alternative decision structure c. Test expression d. Nested decision structure

Multiple alternative decision structure

What is the value of ans after the following code has been executed? int x = 40; int y = 40; int ans = 0; if (x = y) ans = x + 10; a. 50 b. 80 c. 30 d. No value, this is a syntax error.

No value, this is a syntax error.

A block of code is enclosed in a set of: a. double quotes " " b. braces { } c. brackets [ ] d. parentheses ( )

braces { }

The ________ statement is used to make simple decisions in Java. a. for b. branch c. if d. do/while

if

In an if/else statement, if the boolean expression is false: a. the first statement or block is executed b. no statements or blocks are executed c. all statements or blocks are executed d. the statement or block following the else is executed

the statement or block following the else is executed

What will be printed when the following code is executed? int y = 10; if (y == 10) { int x = 30; x += y; } System.out.print("x + "); System.out.print(x); a. x is unknown when the last statement is executed. b. x = 20 c. x = 40 d. x = 30

x is unknown when the last statement is executed.


Related study sets

True or false. Chapter 11 business

View Set

Block 2 Taylor's Skills Quizzes: Peripheral Venous Access, IV, and PICC

View Set

science brain pop questions for quiz- state of matter

View Set

Test 4--Thyroid and parathyroid--Old and New Book

View Set

Percent Yield & Limiting Reactants

View Set