• Home
  • Textbooks
  • Java Programming
  • Making Decisions.

Java Programming

Joyce Farrell

Chapter 5

Making Decisions. - all with Video Answers

Educators


Section 1

Review Questions

Problem 1

The logical structure in which one instruction occurs after another with no branching is a ____________.
a. sequence
b. selection
c. loop
d. case

Check back soon!

Problem 2

Which of the following is typically used in a flowchart to indicate a decision?
a. square
b. rectangle
c. oval
d. diamond

Check back soon!

Problem 3

Which of the following is not a type of if statement?
a. single-alternative
b. dual-alternative
c. reverse
d. nested

Check back soon!

Problem 4

A decision is based on a(n) ____________ value.
a. Boolean
b. absolute
c. definitive
d. convoluted

Check back soon!
01:26

Problem 5

In Java, the value of (14 > 7) is ____________.
a. true
b. false
c. 14
d. 7

Pammi Eswari
Pammi Eswari
Numerade Educator
02:19

Problem 6

Assuming the variable score has been assigned the value 9, which of the following does not display XXX?
a. if(score <= 9) System.out.println("XXX");
b. if(score > 9); System.out.println("XXX");
c. if(score > 0); System.out.println("XXX");
d. if(score == 5) System.out.println("XXX");

Ernest Castorena
Ernest Castorena
Numerade Educator

Problem 7

What is the output of the following code segment?
t = 10;
if(t > 7)
{
System.out.print("AAA");
System.out.print("BBB");
}
a. AAA
b. BBB
c. AAABBB
d. nothing

Check back soon!

Problem 8

What is the output of the following code segment?
t = 0;
if(t > 7)
System.out.print("AAA");
System.out.print("BBB");
a. AAA
b. BBB
c. AAABBB
d. nothing

Check back soon!

Problem 9

What is the output of the following code segment?
t = 7;
if(t > 7)
{
System.out.print("AAA");
System.out.print("BBB");
}
a. AAA
b. BBB
c. AAABBB
d. nothing

Check back soon!

Problem 10

When you code an if statement within another if statement, the statements are ____________.
a. notched
b. nested
c. nestled
d. sheltered

Check back soon!
01:01

Problem 11

The operator that combines two conditions into a single Boolean value that is true only when both of the conditions are true is ____________.
a. $$ \$ \$ $$
b. $\& \&$
c. ||
d. !!

Ernest Castorena
Ernest Castorena
Numerade Educator
01:01

Problem 12

The operator that combines two conditions into a single Boolean value that is true when at least one of the conditions is true is ____________.
a. ||
b. !!
c. $$ \$ \$ $$
d. &&

Ernest Castorena
Ernest Castorena
Numerade Educator
03:04

Problem 13

Assuming a variable f has been initialized to 5, which of the following statements sets g to 0?
a. if(f > 6 || f != 5) g = 0;
b. if(f < 3 || f > 9) g = 0;
c. if(f >= 0 || f < 2) g = 0;
d. if(f == 0 || f == 2) g = 0;

Ernest Castorena
Ernest Castorena
Numerade Educator

Problem 14

Which of the following has the lowest precedence?
a. <
b. ==
c. &&
d. ||

Check back soon!

Problem 15

Which of the following statements correctly outputs the names of voters who live in district 6 and voters who live in district 7?
a. if(district == 6 || 7)
System.out.println("Name is " + name);
b. if(district == 6 || district == 7)
System.out.println("Name is " + name);
c. if(district = 6 && district == 7)
System.out.println("Name is " + name);
d. if(district != 6 && district != 7)
System.out.println("Name is " + name);

Check back soon!

Problem 16

Which of the following displays Error when a student ID is less than 1,000 or more than 9999 ?
a. if(stuId < 1000) if(stuId > 9999)
System.out.println("Error");
b. if(stuId < 1000 && stuId > 9999)
System.out.println("Error");
c. if(stuId < 1000)
System.out.println("Error");
else
if(stuId > 9999)
System.out.println("Error");
d. if(stuId < 1000 || > 9999)
System.out.println("Error");

Check back soon!

Problem 17

You can use the ____________ statement to terminate a switch statement.
a. switch
b. break
c. case
d. end

Check back soon!
02:30

Problem 18

Which of the following cannot be the argument tested in a switch statement?
a. int
b. char
c. double
d. String

Ernest Castorena
Ernest Castorena
Numerade Educator

Problem 19

Assuming a variable w has been assigned the value 15, what does the following statement do?
w == 15 ? x = 2 : x = 0;
a. assigns 15 to w
b. assigns 2 to x
c. assigns 0 to x
d. nothing

Check back soon!

Problem 20

Assuming a variable y has been assigned the value 6, the value of !(y < 7) is ____________.
a. 6
b. 7
c. true
d. false

Check back soon!