Programming Fundamentals I (Chapter 3) – Flashcards
Unlock all answers in this set
Unlock answersquestion
What does the following code display?
int d = 9, e = 12;
System.out.printf("%d %dn", d, e);
Question options:
a) 9 12
b) %9 %12
c) %d 9
d) %d %d
answer
a) 9 12
question
The switch statement is a:
a) Sequence structure.
b) Multiple alternative decision structure.
c) Test expression.
d) Nested decision structure.
answer
b) Multiple alternative decision structure
question
Which of the following correctly tests the char variable chr to determine whether it is not equal to the character B?
a) if (chr < 'B')
b) if (chr != 'B')
c) if (chr > 'B')
d) if (chr != "B")
answer
b) if ( chr != 'B' )
question
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")
answer
a) if (chr == 'a' )
question
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) 30
b) 25
c) 5
d) 20
answer
d) 20
question
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;
a) .04
b) .03
c) .05
d) 0
answer
a) .04
question
This type of operator determines whether a specific relationship exists between two values:
a) Unary
b) Logical
c) Relational
d) Mathematical
answer
c) Relational
question
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;
a) .03
b) .01
c) .05
d) 0.0
answer
d) 0.0
question
If you prematurely terminate an if statement with a semicolon, the compiler will:
a) Assume you are placing a null statement there.
b) Not display an error message.
c) All of the above.
d) None of the above.
answer
d) All of the above.
question
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) .04
b) 0.0
c) .08
d) .06
answer
b) 0.0
question
This is an international coding system that is extensive enough to represent all the characters of all the world's alphabets:
a) Unicode.
b) Java.
c) ASCII.
d) None of the above.
answer
a) Unicode
question
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
answer
c) 1000
question
What will be printed when the following code is executed?
double x = 45678.259;
DecimalFormat formatter =
new DecimalFormat("#,###,##0.00");
System.out.println(formatter.format(x));
a) 45,678.26
b) 45,678.3
c) 0,045,678.26
d) 45678.259
answer
a) 45,678.26
question
A block of code is enclosed in a set of:
a) parentheses ( )
b) double quotes " "
c) brackets [ ]
d) braces { }
answer
c) braces { }
question
The expression tested by an if statement must evaluate to:
a) 0 or 1
b) t or f
c) true or false
d) +1 or -1
answer
c) true or false
question
Programs never need more than one path of execution.
Question options:
True
False
answer
False
question
When testing for character values, the switch statement does not test for the case of the character.
Question options:
True
False
answer
False
question
An important style rule you should follow when writing if statements is to line up the conditionally executed statement with the if statement.
Question options:
True
False
answer
False
question
A local variable's scope always ends at the closing brace of the block of code in which it is declared.
Question options:
True
False
answer
True
question
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.
Question options:
True
False
answer
True