Java Chapter 3

1) The ________ statement is used to make simple decisions in Java.
A) do/while
B) for
C) branch
D) if

d) if

2) A Boolean expression is one that is either:
A) true or false
B) x or y
C) Positive or negative
D) None of the above

a) true or false

3) This type of operator determines whether a specific relationship exists between two values:
A) Logical
B) Mathematical
C) Unary
D) Relational

d) relational

4) Which of the following expressions will determine whether x is less than or equal to y?
A) x > y
B) x =< y
C) x <= y
D) x >= y

c) x<=y

5) Which one of the following is the not equal operator?
A) &lt;&gt;
B) NOT
C) *&amp;
D) !=

d) !=

6) What will be the value of x after the following code is executed?
int x = 75;
int y = 60;
if (x &gt; y)
x = x - y;
A) 75
B) 15
C) 60
D) 135

b) 15

7) 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 &gt;= y)
ans = x + y;
A) 10
B) 120
C) 100
D) No value, there is a syntax error.

b) 120

8) 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

c) 20

9) A block of code is enclosed in a set of:
A) braces { }
B) parentheses ( )
C) double quotes " "
D) brackets

a) braces { }

10) A flag may have the values:
A) 0 or 1
B) +1 or -1
C) true or false
D) of any character

c) true or false

11) 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')

d) if *chr == 'a')

12) In Java, when a character is stored in memory, it is actually stored as a(n):
A) Unicode number
B) ASCII character code
C) EBCDIC character code
D) Morse code

A) unicode number

13) 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 the above

b) unicode

14) 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 &gt;= y)
{
ans = x + 10;
x -=y;
}
else
{
ans = y + 10;
y += x;
}
A) ans = 60, x = 50, y =100
B) ans = 60, x =0, y =50
C) ans = 45, x = 50, y = 0
D) ans = 45, x = 50, y = 50

b) ans = 60, x= 0, y=50

15) What will be the value of bonus after the following code is executed?
int bonus, sales = 10000;
if (sales &lt; 5000)
bonus = 200;
else if (sales &lt; 7500)
bonus = 500;
else if (sales &lt; 10000)
bonus = 750;
else if (sales &lt; 20000)
bonus = 1000;
else
bonus = 1250;
A) 200
B) 500
C) 750
D) 1000
E) 1250

d) 1000

16) In most editors, you are indenting by one level each time that you press this key:
A) Tab
B) Shift
C) Alt
D) Space

A) tab

17) 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 the above
D) None of the above

C) all of the above

18) What would be the value of bonus after the following statements are executed?
int bonus, sales = 1250;
if (sales &gt; 1000)
bonus = 100;
if (sales &gt; 750)
bonus = 50;
if (sales &gt; 500)
bonus = 25;
else
bonus = 0;
A) 100
B) 500
C) 25
D) 0

c) 25

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

d) 1000

20) 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?
A) ((x &gt;= 500 &amp;&amp; x &lt;= 650) &amp;&amp; (y != 1000))
B) ((x &gt; 500 AND x &lt; 650) OR !(y.equal(1000)))
C) ((x &gt; 500 &amp;&amp; x &lt; 650) || (y != 1000))
D) ((x &lt; 500 &amp;&amp; x &gt; 650) || !(y == 1000))

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

21) ________ works like this: If the expression on the left side of the &amp;&amp; operator is false, the expression
the right side will not be checked.
A) Short-circuit evaluation
B) Reverse logic
C) Boolean logic
D) Relational evaluation

a) short-circuit evaluation

22) If str1 and str2 are both Strings, which of the following will correctly test to determine whether
str1 is less than str2?
(1) (str1 &lt; str2)
(2) (str1.equals(str2) &lt; 0)
(3) (str1.compareTo(str2) &lt; 0)
A) 1, 2, and 3 will all work
B) 2
C) 3
D) 2 and 3

C) 3

23) 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 A
D) A and B

D) a and b

24) What will be the value of pay after the following statements are executed?
int hours = 45;
double pay, payRate = 10.00;
pay = hours &lt;= 40 ? hours * payRate :
40 <b> payRate + (hours - 40) </b> payRate * 1.5;
A) 400.00
B) 450.00
C) 465.00
D) 475.00

D) 475.00

25) 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;
}
A) 5
B) 20
C) 25
D) 30

B) 20

26) What will be printed when the following code is executed?
double x = 45678.259;
System.out.printf("%,.2f", x);
A) 45678.259
B) 0,045,678.26
C) 45,678.26
D) 45,678.3

C) 45,678.26

27) Which of the following will format 12.78 to display as 12.8%?
A) System.out.printf("%2.1d%", 12.78);
B) System.out.printf("%.2f%%", 12.78);
C) System.out.printf("%1.2d%", 12.78);
D) System.out.printf("%.1f%%", 12.78);

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

28) The expression tested by an if statement must evaluate to:
A) 0 or 1
B) +1 or -1
C) true or false
D) t or f

c) true or false

29) These operators use two operands:
A) Unary
B) Binary
C) Tertiary
D) None of the above

B) binary

30) 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) 75
B) 90
C) 15
D) 165

D) 165

31) 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.

D) no value, this is a syntax error.

32) What is the value of ans after the following code has been executed?
int x = 35;
int y = 20, ans = 80;
if (x &lt; y);
ans += y;
A) 80
B) 100
C) 35
D) 55

B) 100

33) 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

A) block of statements

34) This is a boolean variable that signals when some condition exists in the program:
A) Sentinel
B) Block
C) Flag
D) Case

C) flag

35) Which of the following correctly tests the char variable chr to determine whether it is NOT equal to
the character B?
A) if (chr &gt; 'B')
B) if (chr &lt; 'B')
C) if (chr != 'B')
D) if (chr != "B")

C) if (chr != 'B')

36) In an if/else statement, if the boolean expression is false:
A) the first statement or block is executed
B) the statement or block following the else is executed
C) all statements or blocks are executed
D) no statements or blocks are executed

B) the statements or block following the else is executed

37) 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 &gt;= y)
{
ans = x + 10;
x -=y;
}
else
{
ans = y + 10;
y += x;
}
A) ans = 0, x = 15, y = 25
B) ans = 25, x = -10, y = 25
C) ans = 35, x = 15, y = 40
D) ans = 25, x = 15, y = 40

c) ans = 35, x = 15, y = 40

38) What would be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
int purchase = 100;
if (purchase &gt; 1000)
discountRate = .05;
else if (purchase &gt; 750)
discountRate = .03;
else if (purchase &gt; 500)
discountRate = .01;
A) .05
B) .03
C) .01
D) 0.0

D) 0.0

39) What would be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
int purchase = 1250;
9
if (purchase &gt; 1000)
discountRate = .05;
if (purchase &gt; 750)
discountRate = .03;
if (purchase &gt; 500)
discountRate = .01;
else
discountRate = 0;
A) .05
B) .03
C) .01
D) 0

C) .01

40) 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 &gt; 1000)
if (cust == 'Y')
discountRate = .05;
else
discountRate = .04;
else if (purchase &gt; 750)
if (cust == 'Y')
discountRate = .04;
else
discountRate = .03;
else
discountRate = 0;
A) .05
B) .04
C) .03
D) 0

B) .04

41) 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?
A) ((x &gt;= 500 &amp;&amp; x &lt;650) &amp;&amp; (y != 1000))
B) ((x &lt;= 500 OR x &gt; 650) AND !(y.equal(1000)))
C) ((x &gt;= 500 || x &lt; 650) || (y != 1000))
D) ((x &lt;= 500 || x &gt; 650) &amp;&amp; !(y == 1000))

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

42) 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, 2, and 3 will all work
B) 1 and 2
C) 1 and 3
D) 2 and 3

D) 2 and 3

43) 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 = 30
B) x = 40
C) x = 20
D) x is unknown when the last statement is executed.

D) x is unknown when the last statement is executed

44) The switch statement is a:
A) Multiple alternative decision structure
B) Nested decision structure
C) Sequence structure
D) Test expression

A) multiple alternative decision structure

45) What will be the value of charges after the following code is executed?
double charges, rate = 7.00;
int time = 180;
charges = time &lt;= 119 ? rate * 2 :
time / 60.0 * rate;
A) 7.00
B) 14.00
C) 21.00
D) 28.00

C) 21.00

46) 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;
}
A) .08
B) .06
C) .04
D) 0.0

D0 0.0

47) 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) 45678.259
B) 45,678.259
C) 45,678.26
D) 45,678.3

D) 45,678.3

48) Which of the following will format 12.7801 to display as $12.78?
A) System.out.printf("$%,.2f", 12.7801);
B) System.out.printf("%f", 12.7801);
C) System.out.printf("%.2f$$", 12.7801);
D) System.out.printf("$d", 12.7801);

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

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

B) 9 12

50) What does the following code display?
double x = 12.3798146;
System.out.printf("%.2f\n", x);
A) 123798146
B) 1238
C) %12.38
D) 12.38

D) 12.38

T/F: Programs never need more than one path of execution.

FALSE

T/F: An important style rule you should adopt for writing if statements is to write the conditionally
executed statement on the line after the if statement.

TRUE

T/F: The if/else statement will execute one group of statements if its boolean expression is true or
another group if its boolean expression is false.

TRUE

T/F: Because the &amp;&amp; operator performs short-circuit evaluation, your boolean expression will usually
execute faster if the subexpression that is most likely false is on the left of the &amp;&amp; operator.

True

T/F: A local variable's scope always ends at the closing brace of the block of code in which it is declared.

True

T/F: When testing for character values, the switch statement does not test for the case of the character

False

T/F: An important style rule you should follow when writing if statements is to line up the conditionally
executed statement with the if statement.

False

T/F: Unicode is an international encoding system that is extensive enough to represent ALL the characters
of ALL the world's alphabets.

true

T/F: Because the || operator performs short-circuit evaluation, your boolean expression will generally be
evaluated faster if the subexpression that is most likely to be true is on the left.

True

T/F: When two Strings are compared using the compareTo method, the cases of the two strings are not
considered.

False

T/F: In a switch statement, each of the case values must be unique.

True

T/F: In a switch statement, if two different values for the CaseExpression would result in the same code
being executed, you must have two copies of the code, one after each CaseExpression.

False

T/F: The String.format method works exactly like the System.out.printf method, except that it
does not display the formatted string on the screen.

True

T/F: The System.out.printf method formats a string and displays it in the console window.

True

Java Chapter 3 - Subjecto.com

Java Chapter 3

Your page rank:

Total word count: 2222
Pages: 8

Calculate the Price

- -
275 words
Looking for Expert Opinion?
Let us have a look at your work and suggest how to improve it!
Get a Consultant

1) The ________ statement is used to make simple decisions in Java.
A) do/while
B) for
C) branch
D) if

d) if

2) A Boolean expression is one that is either:
A) true or false
B) x or y
C) Positive or negative
D) None of the above

a) true or false

3) This type of operator determines whether a specific relationship exists between two values:
A) Logical
B) Mathematical
C) Unary
D) Relational

d) relational

4) Which of the following expressions will determine whether x is less than or equal to y?
A) x &gt; y
B) x =&lt; y
C) x &lt;= y
D) x &gt;= y

c) x<=y

5) Which one of the following is the not equal operator?
A) &lt;&gt;
B) NOT
C) *&amp;
D) !=

d) !=

6) What will be the value of x after the following code is executed?
int x = 75;
int y = 60;
if (x &gt; y)
x = x – y;
A) 75
B) 15
C) 60
D) 135

b) 15

7) 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 &gt;= y)
ans = x + y;
A) 10
B) 120
C) 100
D) No value, there is a syntax error.

b) 120

8) 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

c) 20

9) A block of code is enclosed in a set of:
A) braces { }
B) parentheses ( )
C) double quotes " "
D) brackets [ ]

a) braces { }

10) A flag may have the values:
A) 0 or 1
B) +1 or -1
C) true or false
D) of any character

c) true or false

11) 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’)

d) if *chr == ‘a’)

12) In Java, when a character is stored in memory, it is actually stored as a(n):
A) Unicode number
B) ASCII character code
C) EBCDIC character code
D) Morse code

A) unicode number

13) 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 the above

b) unicode

14) 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 &gt;= y)
{
ans = x + 10;
x -=y;
}
else
{
ans = y + 10;
y += x;
}
A) ans = 60, x = 50, y =100
B) ans = 60, x =0, y =50
C) ans = 45, x = 50, y = 0
D) ans = 45, x = 50, y = 50

b) ans = 60, x= 0, y=50

15) What will be the value of bonus after the following code is executed?
int bonus, sales = 10000;
if (sales &lt; 5000)
bonus = 200;
else if (sales &lt; 7500)
bonus = 500;
else if (sales &lt; 10000)
bonus = 750;
else if (sales &lt; 20000)
bonus = 1000;
else
bonus = 1250;
A) 200
B) 500
C) 750
D) 1000
E) 1250

d) 1000

16) In most editors, you are indenting by one level each time that you press this key:
A) Tab
B) Shift
C) Alt
D) Space

A) tab

17) 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 the above
D) None of the above

C) all of the above

18) What would be the value of bonus after the following statements are executed?
int bonus, sales = 1250;
if (sales &gt; 1000)
bonus = 100;
if (sales &gt; 750)
bonus = 50;
if (sales &gt; 500)
bonus = 25;
else
bonus = 0;
A) 100
B) 500
C) 25
D) 0

c) 25

What would be the value of bonus after the following statements are executed?
int bonus, sales = 85000;
char dept = ‘S’;
if (sales &gt; 100000)
if (dept == ‘R’)
bonus = 2000;
else
bonus = 1500;
else if (sales &gt; 75000)
if (dept == ‘R’)
bonus = 1250;
else
bonus = 1000;
else
bonus = 0;
A) 2000
B) 1500
C) 1250
D) 1000

d) 1000

20) 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?
A) ((x &gt;= 500 &amp;&amp; x &lt;= 650) &amp;&amp; (y != 1000))
B) ((x &gt; 500 AND x &lt; 650) OR !(y.equal(1000)))
C) ((x &gt; 500 &amp;&amp; x &lt; 650) || (y != 1000))
D) ((x &lt; 500 &amp;&amp; x &gt; 650) || !(y == 1000))

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

21) ________ works like this: If the expression on the left side of the &amp;&amp; operator is false, the expression
the right side will not be checked.
A) Short-circuit evaluation
B) Reverse logic
C) Boolean logic
D) Relational evaluation

a) short-circuit evaluation

22) If str1 and str2 are both Strings, which of the following will correctly test to determine whether
str1 is less than str2?
(1) (str1 &lt; str2)
(2) (str1.equals(str2) &lt; 0)
(3) (str1.compareTo(str2) &lt; 0)
A) 1, 2, and 3 will all work
B) 2
C) 3
D) 2 and 3

C) 3

23) 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 A
D) A and B

D) a and b

24) What will be the value of pay after the following statements are executed?
int hours = 45;
double pay, payRate = 10.00;
pay = hours &lt;= 40 ? hours * payRate :
40 <b> payRate + (hours – 40) </b> payRate * 1.5;
A) 400.00
B) 450.00
C) 465.00
D) 475.00

D) 475.00

25) 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;
}
A) 5
B) 20
C) 25
D) 30

B) 20

26) What will be printed when the following code is executed?
double x = 45678.259;
System.out.printf("%,.2f", x);
A) 45678.259
B) 0,045,678.26
C) 45,678.26
D) 45,678.3

C) 45,678.26

27) Which of the following will format 12.78 to display as 12.8%?
A) System.out.printf("%2.1d%", 12.78);
B) System.out.printf("%.2f%%", 12.78);
C) System.out.printf("%1.2d%", 12.78);
D) System.out.printf("%.1f%%", 12.78);

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

28) The expression tested by an if statement must evaluate to:
A) 0 or 1
B) +1 or -1
C) true or false
D) t or f

c) true or false

29) These operators use two operands:
A) Unary
B) Binary
C) Tertiary
D) None of the above

B) binary

30) 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) 75
B) 90
C) 15
D) 165

D) 165

31) 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.

D) no value, this is a syntax error.

32) What is the value of ans after the following code has been executed?
int x = 35;
int y = 20, ans = 80;
if (x &lt; y);
ans += y;
A) 80
B) 100
C) 35
D) 55

B) 100

33) 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

A) block of statements

34) This is a boolean variable that signals when some condition exists in the program:
A) Sentinel
B) Block
C) Flag
D) Case

C) flag

35) Which of the following correctly tests the char variable chr to determine whether it is NOT equal to
the character B?
A) if (chr &gt; ‘B’)
B) if (chr &lt; ‘B’)
C) if (chr != ‘B’)
D) if (chr != "B")

C) if (chr != ‘B’)

36) In an if/else statement, if the boolean expression is false:
A) the first statement or block is executed
B) the statement or block following the else is executed
C) all statements or blocks are executed
D) no statements or blocks are executed

B) the statements or block following the else is executed

37) 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 &gt;= y)
{
ans = x + 10;
x -=y;
}
else
{
ans = y + 10;
y += x;
}
A) ans = 0, x = 15, y = 25
B) ans = 25, x = -10, y = 25
C) ans = 35, x = 15, y = 40
D) ans = 25, x = 15, y = 40

c) ans = 35, x = 15, y = 40

38) What would be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
int purchase = 100;
if (purchase &gt; 1000)
discountRate = .05;
else if (purchase &gt; 750)
discountRate = .03;
else if (purchase &gt; 500)
discountRate = .01;
A) .05
B) .03
C) .01
D) 0.0

D) 0.0

39) What would be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
int purchase = 1250;
9
if (purchase &gt; 1000)
discountRate = .05;
if (purchase &gt; 750)
discountRate = .03;
if (purchase &gt; 500)
discountRate = .01;
else
discountRate = 0;
A) .05
B) .03
C) .01
D) 0

C) .01

40) 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 &gt; 1000)
if (cust == ‘Y’)
discountRate = .05;
else
discountRate = .04;
else if (purchase &gt; 750)
if (cust == ‘Y’)
discountRate = .04;
else
discountRate = .03;
else
discountRate = 0;
A) .05
B) .04
C) .03
D) 0

B) .04

41) 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?
A) ((x &gt;= 500 &amp;&amp; x &lt;650) &amp;&amp; (y != 1000))
B) ((x &lt;= 500 OR x &gt; 650) AND !(y.equal(1000)))
C) ((x &gt;= 500 || x &lt; 650) || (y != 1000))
D) ((x &lt;= 500 || x &gt; 650) &amp;&amp; !(y == 1000))

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

42) 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, 2, and 3 will all work
B) 1 and 2
C) 1 and 3
D) 2 and 3

D) 2 and 3

43) 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 = 30
B) x = 40
C) x = 20
D) x is unknown when the last statement is executed.

D) x is unknown when the last statement is executed

44) The switch statement is a:
A) Multiple alternative decision structure
B) Nested decision structure
C) Sequence structure
D) Test expression

A) multiple alternative decision structure

45) What will be the value of charges after the following code is executed?
double charges, rate = 7.00;
int time = 180;
charges = time &lt;= 119 ? rate * 2 :
time / 60.0 * rate;
A) 7.00
B) 14.00
C) 21.00
D) 28.00

C) 21.00

46) 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;
}
A) .08
B) .06
C) .04
D) 0.0

D0 0.0

47) 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) 45678.259
B) 45,678.259
C) 45,678.26
D) 45,678.3

D) 45,678.3

48) Which of the following will format 12.7801 to display as $12.78?
A) System.out.printf("$%,.2f", 12.7801);
B) System.out.printf("%f", 12.7801);
C) System.out.printf("%.2f$$", 12.7801);
D) System.out.printf("$d", 12.7801);

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

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

B) 9 12

50) What does the following code display?
double x = 12.3798146;
System.out.printf("%.2f\n", x);
A) 123798146
B) 1238
C) %12.38
D) 12.38

D) 12.38

T/F: Programs never need more than one path of execution.

FALSE

T/F: An important style rule you should adopt for writing if statements is to write the conditionally
executed statement on the line after the if statement.

TRUE

T/F: The if/else statement will execute one group of statements if its boolean expression is true or
another group if its boolean expression is false.

TRUE

T/F: Because the &amp;&amp; operator performs short-circuit evaluation, your boolean expression will usually
execute faster if the subexpression that is most likely false is on the left of the &amp;&amp; operator.

True

T/F: A local variable’s scope always ends at the closing brace of the block of code in which it is declared.

True

T/F: When testing for character values, the switch statement does not test for the case of the character

False

T/F: An important style rule you should follow when writing if statements is to line up the conditionally
executed statement with the if statement.

False

T/F: Unicode is an international encoding system that is extensive enough to represent ALL the characters
of ALL the world’s alphabets.

true

T/F: Because the || operator performs short-circuit evaluation, your boolean expression will generally be
evaluated faster if the subexpression that is most likely to be true is on the left.

True

T/F: When two Strings are compared using the compareTo method, the cases of the two strings are not
considered.

False

T/F: In a switch statement, each of the case values must be unique.

True

T/F: In a switch statement, if two different values for the CaseExpression would result in the same code
being executed, you must have two copies of the code, one after each CaseExpression.

False

T/F: The String.format method works exactly like the System.out.printf method, except that it
does not display the formatted string on the screen.

True

T/F: The System.out.printf method formats a string and displays it in the console window.

True

Share This
Flashcard

More flashcards like this

NCLEX 10000 Integumentary Disorders

When assessing a client with partial-thickness burns over 60% of the body, which finding should the nurse report immediately? a) ...

Read more

NCLEX 300-NEURO

A client with amyotrophic lateral sclerosis (ALS) tells the nurse, "Sometimes I feel so frustrated. I can’t do anything without ...

Read more

NASM Flashcards

Which of the following is the process of getting oxygen from the environment to the tissues of the body? Diffusion ...

Read more

Unfinished tasks keep piling up?

Let us complete them for you. Quickly and professionally.

Check Price

Successful message
sending