Java Quiz 3

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

if (chr == 'a')

If chr is a character variable, which of the following if statements is written correctly?

Unicode number

In Java, when a character is stored in memory, it is actually stored as a(n):

the statement or block following the else is executed

In an if/else statement, if the boolean expression is false:

!=

Which one of the following is not the equal operator?

9 12

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

Binary

These operators use two operands:

12.38

What does the following code display? double x = 12.3798146; System.out.printf("%.2f\n", x);

45,678.3

What will be printed when the following code is executed? double x = 45678.259; String output = String.format("%,.1f", x); System.out.println(output);

true or false

A flag may have the values:

Flag

This is a boolean variable that signals when some condition exists in the program:

block of statements

Enclosing a group of statements inside a set of braces creates a:

(2) str1.equals(str2) (3)(str1.compareTo(str2) == 0)

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)

(3) (str1.compareTo(str2) < 0)

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)

All of these (Not display an error message & Assume you are placing a null statement there)

If you prematurely terminate an if statement with a semicolon, the compiler will:

Tab

In most editors, you are indenting by one level each time that you press this key:

if

The ___ statement is used to make simple decisions in Java.

true or false

The expression tested by an if statement must evaluate to:

Unicode

This is an international coding system that is extensive enough to represent all the characters of all the world's alphabets:

Relational

This type of operator determines whether a specific relationship exists between two values:

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

To do a case insensitive compare which of the following could be used to test the equality of two strings, str1 and str2?

100

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;

No value, this is a syntax error.

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;

165

What is the value of x after the following code has been executed? int x = 75; int y = 90; if (x != y) x += y;

45,678.26

What will be printed when the following code is executed? double x = 45678.259; System.out.printf("%,.2f", x);

x is unknown when the last statement 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);

120

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;

20

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;

1000

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;

21.00

What will be the value of charges after the following code is executed? double charges, rate = 7.00; int time = 180; charges = time <= 119 ? rate * 2 : time / 60.0 * rate;

475.00

What will be the value of pay after the following statements are executed? int hours = 45; double pay, payRate = 10.00; pay = hours <= 40 ? hours * payRate : 40 * payRate + (hours - 40) * payRate * 1.5;

15

What will be the value of x after the following code is executed? int x = 75; int y = 60; if (x > y) x= x - y;

ans = 35, x = 15, y = 40

What will be the values of ans, x, and y after the following statements are executed? int ans = 0, x = 15, y = 25; if (x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; }

ans = 60, x =0, y =50

What will be the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y = 50; if (x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; }

25

What would be the value of bonus after the following statements are executed? int bonus, sales = 1250; if (sales > 1000) bonus = 100; if (sales > 750) bonus = 50; if (sales > 500) bonus = 25; else bonus = 0;

1000

What would be the value of bonus after the following statements are executed? int bonus, sales = 85000; char dept = 'S'; if (sales > 100000) if (dept == 'R') bonus = 2000; else bonus = 1500; else if (sales > 75000) if (dept == 'R') bonus = 1250; else bonus = 1000; else bonus = 0;

0.0

What would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 100; if (purchase > 1000) discountRate = .05 else if (purchase > 750) discountRate = .03; else if (purchase > 500) discountRate = .01;

.04

What would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; char cust = 'N'; if (purchase > 1000) if (cust == 'Y') discountRate = .05; else discountRate = .04; else if (purchase > 750) if (cust == 'Y') discountRate = .04; else discountRate = .03; else discountRate = 0;

.01

What would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; if (purchase > 1000) discountRate = .05 if (purchase > 750) discountRate = .03; if (purchase > 500) discountRate = .01; else discountRate = 0;

0.0

What would be the value of discountRate after the following statements are executed? double discountRate; char custType = 'B'; switch (custType) { case 'A' : discountRate = .08; break; case 'B' : discountRate = .06; case 'C' : discountRate = .04; default : discountRate = 0.0; }

20

What would be the value of x after the following statements were executed? int x = 10 switch (x) { case 10: x += 15; case 12: x -= 5; break; default: x *= 3; }

if (chr != 'B')

Which of the following correctly tests the char variable chr to determine whether it is NOT equal to the character B?

x <= y

Which of the following expressions will determine whether x is less than or equal to y?

((x > 500 && x < 650) || (y != 1000))

Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?

((x <= 500 || x > 650) && !(y == 1000))

Which of the following is the correct boolean expression to test for: int x being a value less than or equal to 500 or greater than 650, and int y not equal to 1000?

System.out.printf("%.1f%%", 12.78);

Which of the following will format 12.78 to display as 12.8%?

System.out.printf("$%,.2f", 12.7801);

Which of the following will format 12.7801 to display as $12.78?

Short-circuit evaluation

________ works like this: If the expression on the left side of the && operator is false, the expression the right side will not be checked.

Multiple alternative decision structure

The switch statement is a:

true or false

A Boolean expression is one that is either:

braces { }

A block of code is enclosed in a set of:


Ensembles d'études connexes

Macroeconomics: Chapter 1 Homework

View Set

The Civil War Study Island Answers

View Set

Experiment 1: UV Analysis of Sunscreens

View Set

ACC201 Chapter 11 (wileyplus) Plattsburgh

View Set

16.3 The Holocaust (Based on PPT)

View Set

SAMPLE MARKETING CLUSTER EXAM #1

View Set