• Home
  • Textbooks
  • Introduction to Programming with Java: A Problem Solving Approach
  • Control Statements

Introduction to Programming with Java: A Problem Solving Approach

John S. Dean, Raymond H. Dean

Chapter 4

Control Statements - all with Video Answers

Educators


Chapter Questions

01:36

Problem 1

What are Java's two Boolean values?

Adithya Ramanujam
Adithya Ramanujam
Numerade Educator
01:13

Problem 2

Provide a list of Java's comparison operators.

SS
Sarvesh Somasundaram
Numerade Educator
00:44

Problem 3

Provide an if statement that implements this logic:
When the water temperature is less than $120^{\circ} \mathrm{F}$, turn the heater on by assigning the value "on" to a heater string variable. When the water temperature is greater than $140^{\circ} \mathrm{F}$, turn the heater off by assigning the value "off" to a heater string variable. Don't do anything when the water temperature is between these two temperatures.

James Kiss
James Kiss
Numerade Educator
01:00

Problem 4

What is the maximum number of "else if " blocks allowed in an if statement that uses the "if, else if", form?

Vikash Ranjan
Vikash Ranjan
Numerade Educator
01:01

Problem 5

The relational and equality operators have higher precedence than the arithmetic operators. (T / F)

Ernest Castorena
Ernest Castorena
Numerade Educator
01:02

Problem 6

Correct the following code fragment so that it executes and outputs OK if a, an int variable, is equal to either 2 or 3:

Vysakh M
Vysakh M
Numerade Educator
00:42

Problem 7

What Java operator reverses the truth or falsity of a condition?

Ashley Volpe
Ashley Volpe
Numerade Educator
02:15

Problem 8

What happens if you forget to include break; at the end of a block of statements after a particular case: label?

Ernest Castorena
Ernest Castorena
Numerade Educator
05:49

Problem 9

If you are trying to substitute a switch statement for an "if, else" statement, you can use the if condition as the controlling expression in the switch statement. (T/F)

Ernest Castorena
Ernest Castorena
Numerade Educator
01:03

Problem 10

Suppose the controlling expression in a switch statement is (stdIn.next().charAt(0)), and you want to allow either 'Q' or 'q' to produce the same result, which is:
System.out.println("quitting"); Write the code fragment for the case that produces this result.

Mohamed Mohamed
Mohamed Mohamed
Numerade Educator
00:46

Problem 11

What must a while loop condition evaluate to?

Anna Jones
Anna Jones
Numerade Educator
00:25

Problem 12

Suppose you want to use the user-query technique to terminate a simple while loop. Where should you put the user query?

Ernest Castorena
Ernest Castorena
Numerade Educator
01:02

Problem 13

What's wrong with this code fragment? int $x=3$
do
\{
\[
x-=2
\]
while $(x>=0)$

Vysakh M
Vysakh M
Numerade Educator
00:46

Problem 14

If you know ahead of time the exact number of iterations through a loop, what type of loop should you use?

Nick Johnson
Nick Johnson
Numerade Educator
02:57

Problem 15

Implement the following as a for loop:
\[\begin{array}{l}\text { int age }=0 \text { ; } \\\text { while (age }<5 \text { ) }\end{array}\]\{
System.out.println ("Happy Birthday# " + age) age $=$ age +1
I/ end while
What output will your equivalent for loop generate?

Mayank Tripathi
Mayank Tripathi
Numerade Educator
01:17

Problem 16

If you know that a loop should be executed at least one time, what type of loop is most appropriate?

Adam Conner
Adam Conner
Numerade Educator
02:57

Problem 17

Construct a template for a for loop inside a for loop. Use i for the outer for loop's index variable and use j for the inner for loop's index variable.

Mayank Tripathi
Mayank Tripathi
Numerade Educator
01:16

Problem 18

Assume that the variable $O K$ has been declared to be of type boolean. Replace the following code with an equivalent for loop:
\[\mathrm{OK}=\text { false }\]
while (!OK)\{$\langle\text {statement}(s)\rangle$\[j\]

Julie Silva
Julie Silva
Numerade Educator
02:02

Problem 19

Given the logical expression:
\[!(! a \quad|| \quad ! b)\]
Replace it with an equivalent logical expression that is completely devoid of "not" operations.

Nicole Basile
Nicole Basile
Numerade Educator