CIS 283 CH 5
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
When testing for character values, the switch statement does not test for the case of the character.
False
Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 012.8?
"000.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 = 0.05; else if (purchase > 750) discountRate = 0.03; else if (purchase > 500) discountRate = 0.01;
0.0
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 = 0.05; else discountRate = 0.04; else discountRate = 0.03; else discountRate = 0.0;
0.04
What will be the value of bonus after the following code is executed? int bonus, sales = 10000; if (sale < 5000) bonus = 200; else if (sales <7500) bonus = 500; else if (sales < 10000) bonus 750; else if (sales < 20000) bonus = 1000; else bonus = 1250;
1000
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;
15
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; }
20
What will be displayed after the following statements are executed? int hours = 30; double pay, payRate = 10.00; pay = hours <= 40? hours * payRate : hours * payRate * 2.0; Sytem.out.println(pay;
300.0
What will be displayed when the following code is executed? double x = 45678.259; DecimalFormat formatter = new DecimalFormat ("#,###,##0.00"); JOptionPane.showMessageDialog(null,formatter.format (x));
45,678.26
What will be displayed when the following code is executed? double x = 45678.259; DecimalFormat formatter = new DecimalFormat ("#,##0.0"); JOptionPane.showMessageDIalog(null,formatter.format (x));
45,678.3
________ operators are used to determine whether a specific relationship exists between two values.
Relational
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
The DecimalFormat class is part of the Java API, but it is not automatically available to your programs.
True
Unicode is an international encoding system that is extensive enough to represent all the characters of all the world's alphabets.
True
Enclosing a group of statements inside a set of braces creates
a block of statements.
Java requires that the boolean expression being tested by an if statement be enclosed in
a set of parentheses.
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; }
ans = 60, x = 0, y = 50
A block of code is enclosed in a set of
braces
A ________ is a boolean variable that signals when some condition exists in the program.
flag
The ________ statement is used to create a decision structure, which allows a program to have more than one path of execution.
if
If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?
str1.equals(str2)
Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2?
str1.equalsIgnoreCase(str2)
In an if-else statement, if the boolean expression is false
the statement or block following the else is executed.
The boolean expression in an if statement must evaluate to
true or false