You are on page 1of 2

! CS 1114 Fa22 Assignments 03: Condi!onal and Repea!ng Ac!

ons

03: Condi!onal and Repea!ng Ac!ons

Due Sep 11 by 11:59pm Points 100 Submi!ng an external tool

3.1. Conditional and Repeating Actions

3.1.1. Selection

The methods that we have written thus far have a common characteristic–sequential execution. Sequential execution means that the statements are executed one after another in the order that
they appear in the source code. In this chapter, we will learn how to create a block of statements that we can either execute or skip, as well as how we can choose to execute one of multiple
alternative blocks of statements.

A control structure is a feature of a programming language that determines the order in which statements will be executed. There are three categories of control structures: (1) sequential
structures, (2) selection structures, and (3) repetition structures (also called loops).

Sequential structure is the default structure that is used by most object-oriented programming languages: putting one statement after the other, in sequence. Unless we indicate otherwise, the
statements will be executed in the order that they appear in the source code, and each statement will be executed exactly once. Every program that we have seen thus far uses nothing but
sequential structure.

A condition is a crucial part of the selection structures and the repetition structures. A condition is any expression that can be either true or false.

Note

A condition is any expression that can be true or false.

Every selection structure defines two or more alternate paths through the source code. There are three important selection structures: an if-then-else structure, an if-then structure, and a multi-way
branching structure.

An if-then-else structure (sometimes called an if-else structure) is the most fundamental selection structure, since it can be used to form any choice pattern possible. An if-then-else structure
defines two different blocks of statements, only one of which will be executed.

An if-then structure (sometimes called simply an if structure) is a special form of if-then-else where only one block of statements is provided and the second block of statements is omitted. As a
result, an if-then structure defines an optional block of statements, where the block is either executed or skipped.

A multi-way-if structure (sometimes called a multi-way branching structure) defines several different blocks of statements, only one of which will be executed. Java also has a switch structure to
create a multi-way branching structure, but we’ll learn about it later.

3.1.2. Conditions Using Sensor Methods

The Jeroo class provides a number of sensor methods that can be used to ask a Jeroo something about its immediate surroundings. Each sensor method has either a true or a false result. Any
method that produces either true or false as a result is called a boolean method (also called a predicate). More generally, any expression that is either true or false is called a boolean expression
(named after George Boole ). This means that the conditions that are used in various control structures are, in fact, boolean expressions.

Note

Any method that produces either true or false as a result is called a boolean method, also known as a predicate.

For Jeroos, the sensor methods are the basic building blocks for creating conditions. The simplest way to create a condition is to invoke a sensor method. The table below lists all of the sensor
methods provided by the Jeroo class. These methods can only be used to construct conditions. Since they are methods, they are invoked by sending a message to a Jeroo object.

Sensor Methods
Method Purpose Example
hasFlower() Does this Jeroo have any flowers? dean.hasFlower()
isClear(relativeDirection) Is there a clear space in the indicated direction? A clear dean.isClear(LEFT)
space contains no flower, no net, no water, and no
Jeroo. [isClear(HERE) is meaningless]
isFacing(compassDirection) Is this Jeroo facing in the indicated direction? dean.isFacing(NORTH)
seesFlower(relativeDirection) Is there a flower in the indicated direction? dean.seesFlower(HERE)
seesJeroo(relativeDirection) Is there another Jeroo in the indicated direction? dean.seesJeroo(AHEAD)
[seesJeroo(HERE) is meaningless]
seesNet(relativeDirection) Is there a net in the indicated direction? dean.seesJeroo(RIGHT)
[seesNet(HERE) is meaningless]
seesWater(relativeDirection) Is there water in the indicated direction? dean.seesWater(AHEAD)
[seesWater(AHEAD) is meaningless]

Notably, when you see relativeDirection, your choices of direction include HERE, LEFT, RIGHT, and AHEAD. When you see compassDirection, your choices of direction are: NORTH,
SOUTH, EAST, and WEST.

3.1.3. An Overview of Conditional Statements

Coding Basics: If Statements, If Else, Else - Coding …


Share

Watch on

3.1.4. Java’s Syntax for the If-Then-Else Structure

This figure shows the syntax of the if-then-else structure in Java. There are four important things to observe about the syntax.

1. The condition must be in parentheses.

2. There is no semicolon after the parentheses.

3. There is no semicolon after the keyword else.

4. The if-then-else structure is not a method, which means that we do not send it as a message to a Jeroo object.

There are three important things to observe about the coding style.

1. Braces are used to define the beginning and end of both the true branch and the false branch. Always include them.

2. The braces are aligned with the start of the words if and else.

3. The statements between the braces should be indented (we use 4 spaces).

3.1.4.1. Example (if-then-else structure)

Have the Jeroo named Timmy check for a net straight ahead. If there is one, have him disable it and turn around. If there is not a net straight ahead, Timmy should turn right. After he disables the
net and turns around or simply turns right, Timmy must move one space forward.

if (timmy.seesNet(AHEAD))
{
timmy.toss();
timmy.turn(LEFT);
timmy.turn(LEFT);
}
else
{
timmy.turn(RIGHT);
}

timmy.hop();

3.1.4.2. Self-Check

Practicing If-Then-Else Structure Current score: 3 out of 3

For this question, assume a jeroo named martha has a flower immediately ahead if it. Answer

Check Answer
if (martha.seesFlower(AHEAD))
{
martha.hop();
} Need help?
else I'd like a hint
{
martha.hop();
martha.hop();
}

How many times would martha hop?

3.1.5. Syntax Practice 3a: If-Then-Else

Syntax Practice 3a: If-Then-Else 5 X887: Jeroo disables net


100% You are writing code using a jeroo named charles who is currently holding a flower. Change the
condition in this if-then-else statement so that if ` charles sees a net ahead, charles will toss his
flower to disable the net, and otherwise will hop.

" X887: Jeroo disables net


!
You are writing code using a
Your Answer: Feedback
jeroo named charles who 1.0 /
is currently holding a flowe… 1.0 1 if (charles.seesNet(AHEAD))
1.0 /
Change 2 {
Java the
Jeroocondition
methodsin this… 1.0
if-then-else statement... 3   charles.toss();
4 } Result Behavior
5 else
" X888: Jeroo turns away
! 6 {
You are writing code using a # Charles disables the net
7   charles.hop();
jeroo named jamie . Change 1.0 / 8 }
the else clause so that… 1.0
9 Charles hops when there is no
jamie will turnconditionals
right #
Java Jeroo … net
instead of hop when there is
no...

" X889: Jeroo turns right


!
You are writing code using a Check my answer! Reset Next exercise
jeroo named jamie . Change 1.0 /
the code so that jamie wi… 1.0
turn
Javaright if a flower
Jeroo is to the
conditionals …
right, or hop...

" X890: Jeroo if-then-else syntax


!
You are writing code using a
jeroo named jamie . The 1.0 /
following if-then-else… 1.0
statement will not
Java Jeroo compile …
conditionals
because of a syntax error. Fix
the...

" X891: Jeroo sees water


!
You are writing code using a
jeroo named jamie , who is 1.0 /
holding a flower. Change th… 1.0
following if statement
Java Jeroo so …
conditionals
that if jamie sees water
on...

3.1.6. Creating Optional Statements With If-then

An if-then structure (sometimes called an if structure) defines an optional block of statements. An if-then structure is simply an if-then-else structure where the second block of statements (the else
part) has been omitted, so that the choice becomes whether to execute the first block of statements or skip it.

There are two parts to an if structure, the selection condition and the true branch. The true branch contains a block of statements that will only be executed whenever the selection condition is true.

The figure above shows a generic if-then structure, and uses arrows to show the order in which statements will be executed. The if structure defines optional code, and that code is either skipped or
executed just once.

3.1.7. Java’s Syntax for the If-then Structure

This figure shows the syntax of the if-then structure in Java. There are three important things to observe about the syntax.

1. The condition must be in parentheses.

2. There is no semicolon after the parentheses.

3. The if-then structure is not a method, which means that we do not send it as a message to a Jeroo object.

There are three important things to observe about the coding style.

1. Braces are used to define the beginning and end of the true branch. Always include them.

2. The braces are aligned with the start of the word if.

3. The statements between the braces should be indented (we use 4 spaces).

3.1.7.1. Example (if-then structure)

Have the Jeroo named Jessica check for a net to her right. If there is one, have her disable it and return to her current state. Whether or not she disables a net, Jessica should hop one space
ahead.

if (jessica.seesNet(RIGHT))
{
jessica.turn(RIGHT);
jessica.toss();
jessica.turn(LEFT);
}

jessica.hop();

3.1.7.2. Self-Check

Practicing If-Then Structure Current score: 3 out of 3

Assume for this question you have a jeroo named martha who does not have a flower Answer

Check Answer
if (martha.hasFlower())
{
martha.hop();
} Need help?
martha.hop(); I'd like a hint

How many times will this jeroo hop?

Four times

One time

This code will throw an error

Two times.

3.1.8. Syntax Practice 3b: If-Then

Syntax Practice 3b: If-Then 4 X892: Jeroo just turns


100% You are writing code using a jeroo named jaime . Change the following if-then-else statement to an if-
then, so that jaime does nothing if there is no flower to the left.

Your Answer: Feedback


" X892: Jeroo just turns
!
You are writing code using a 1 if (jaime.seesFlower(LEFT))
jeroo named jaime . Change 1.0 / 1.0 /
2 {
the following if-then-else… 1.0 1.0
3   jaime.turn(LEFT);
statement to an conditionals
Java Jeroo if-then, so …
that jaime does nothing
4 } Result Behavior
5
if...
6
# Jaime now behaves correctly
!
" X893: Jeroo always hops 7
You are writing code using a 8
jeroo named jaime . Change 1.0 /
the following if-then-else… 1.0
statement to an conditionals
Java Jeroo if-then …
(remove the else part), so
that...

" X894: Jeroo conditional toss


Check my answer! Reset Next exercise
!
You are writing code using a
jeroo named maria who 1.0 /
already has a flower. Finish… 1.0
writing
Java the if-then
Jeroo statement
conditionals …
below so that maria will...

" X895: Jeroo conditional pick


!
You are writing code using a
jeroo named maria . There 1.0 /
is a mistake in the followin… 1.0
if-then
Java statement. Find and …
Jeroo conditionals
fix the error, so that...

3.1.9. Java’s Syntax for the Multi-way Selection Structure (a cascaded if)

This figure shows a common technique for writing a multi-way selection structure in Java. Technically, this structure consists of a series of nested if-then-else statements, but the coding style
obscures this fact and makes the multi-way selection logic more visible. This particular structure is often called a cascaded if.

There are five important things to observe about this structure.

1. The condition must be in parentheses.

2. There is no semicolon after the parentheses.

3. There is no limit on the number of else-if blocks.

4. The final else branch is optional.

5. This structure is not a method, which means that we do not send it as a message to a Jeroo object.

There are three important things to observe about the coding style.

1. Braces are used to define the beginning and end of the true branch. Always include them.

2. The braces are aligned with the start of the word if and else.

3. The statements between the braces should be indented (we use 4 spaces).

3.1.9.1. Example (multi-way selection structure)

Assume that a Jeroo named Louisa is carrying at least one flower. Have her check the cell ahead. If that cell contains a flower, pick it. If that cell contains a net, disable it. If that cell contains water,
plant a flower at the current location. If that cell contains another Jeroo, give that Jeroo a flower. Finally, if there is nothing in that cell, have her hop once and turn left.

if (louisa.seesFlower(AHEAD))
{
louisa.hop();
louisa.pick();
}
else if (louisa.seesNet(AHEAD))
{
louisa.toss();
}
else if (louisa.seesWater(AHEAD))
{
louisa.plant();
}
else if (louisa.seesJeroo(AHEAD))
{
louisa.give(AHEAD);
}
else
{
louisa.hop();
louisa.turn(LEFT);
}

3.1.9.2. Self-Check

Practicing Using the Right Structure Current score: 3 out of 3

Assume we see an if statement that reads if (!true). What would you know about this code? Answer

Check Answer
This code would cause your computer to restart.

The code inside this conditional would never run.


Need help?
if (!true) would produce a syntax error.
I'd like a hint

The code inside this conditional would always run.

I don't have enough information about the program to answer this question.

This code would compile, but would fail if you tried to run it.

3.1.10. Syntax Practice 3c: Multi-way If

Syntax Practice 3c: Multi-way If 4 X896: Jeroo add else


100% You are writing code using a jeroo named amy . Change the following if-else-if statement by adding an
else so that amy will hop if she doesn't turn left or right.

Your Answer: Feedback


" X896: Jeroo add else
!
You are writing code using a 1 if (amy.seesFlower(LEFT))
jeroo named amy . Change 1.0 / 1.0 /
2 {
the following if-else-if… 1.0 1.0
3   amy.turn(LEFT);
statement by adding
Java Jeroo an
conditionals …
else so that amy will hop
4 } Result Behavior
5 else if (amy.seesFlower(RIGHT))
if she...
6 {
# Amy now behaves correctly
" X897: Jeroo add else-if
! 7   amy.turn(RIGHT);
You are writing code using a 8 }
jeroo named amy . Change 1.0 / 9 else
the following if-then-else… 1.0 10 {
statement by adding
Java Jeroo a new …
conditionals 11   amy.hop();
else-if so that amy will 12 }
turn... 13
14
" X898: Jeroo add else-if-else-if
!
You are writing code using a
jeroo named amy . Change 1.0 / Check my answer! Reset Next exercise
the following if-else-if… 1.0
statement by adding
Java Jeroo a new …
conditionals
else-if so that amy will
turn...

" X899: Jeroo if-else-if-else


!
You are writing code using a
jeroo named amy . Change 1.0 /
the following if-else-if… 1.0
statement
Java Jerooby changing the …
conditionals
third part from an else
only to...

3.1.11. Compound Conditions

Conditions come in two forms, simple and compound. A simple condition is a boolean expression that does not contain any other boolean expression. With Jeroos, a simple condition is formed
by invoking a single sensor method. A compound condition is created by using logical operators to combine conditions. The three most commonly used logical operators in Java are: negation
(not), conjunction (and), and disjunction (or). Java uses special keystrokes for each of these as shown in the following table.

Operators for conditions


Operator Java Symbol Meaning
Negation ! (exclamation point) NOT
Conjunction && (2 keystrokes; no space between) AND
Disjunction || (2 keystrokes; no space between) OR

Java Logical Operators - AND && - OR || - NOT ! - Ja…


Share

Watch on

Notably, java recognizes single & and | as separate operators (they have to do with binary math) from && and ||. No errors will be thrown if you mistake one for the other and your code will simply
behave oddly. Also, ! is a unary operator. It can modify a single if statement but not combine two together.

The negation reverses the value of a boolean expression, changing true to false and false to true, as shown in this table:

In this table, P represents an arbitrary boolean expression. The two rows underneath P show its possible values. The second column shows the corresponding values for the expression !P, where
the negation operator is applied to the boolean expression.

The conjunction operator (&&, representing logical AND) combines two boolean expressions to create a third that is only true when both of the original expressions are true:

In this table, P and Q represent arbitrary boolean expressions. The rows underneath P and Q show all possible combinations of their values. The third column shows the corresponding values for P
&& Q.

The disjunction operator (||, representing logical OR) combines two boolean expressions to create a third that is only false when both of the original expressions are false:

In this table, P and Q once again represent arbitrary boolean expressions. The rows underneath P and Q show all possible combinations of their values. The third column shows the corresponding
values for the expression P || Q.

Boolean Operators and Truth Tables - AP CSA


Share

Watch on

3.1.11.1. Examples (compound conditions)

Remember that these are expressions that could be either true or false. The statement:

boolean x = false;

definitively sets the boolean variable x to false. It is similar to the English statement “the variable x is false”. It is a statement of a fact.

If statements are more like a question:

martha.seesNet(AHEAD)

This expression is more like a question. “Does the jeroo see a net ahead of them?” It could be answered yes or no, but it’s not a statement of a fact in the same way.

Operators for conditions


Boolean Expression (Java-style) English Translation (if true)
!bob.seesNet(AHEAD) There is not a net ahead of Bob
bob.hasFlower() && bob.isClear(LEFT) Bob has at least one flower and there is nothing in the cell immediately to the left of
Bob.
bob.seesWater(AHEAD) || bob.seesWater(RIGHT) There is water ahead of Bob or to the right of Bob, or both
bob.isFacing(WEST) &&(!bob.seesNet(AHEAD)) Bob is facing west and there is no net ahead

3.1.11.2. Self-Check

Practicing AND, OR, and NOT Conditionals Current score: 3 out of 3

Assume boolean variable a is true and boolean variable b is false. Would if (a && b) run the code in the if statement? Answer

Check Answer
No - This code would produce an error.

Yes - at least one boolean is true so the whole statement is true.


Need help?
No - both variables need to be true for the if statement to run.
I'd like a hint

Yes - at least one boolean is false so the whole statement is true.


 

3.1.12. Syntax Practice 3d: Compound Conditions

Syntax Practice 3d: Compound Co… X900: Jeroo looks left and right
100% You are writing code using a jeroo named jaime . Change the following if-then statement's condition so
that jaime will hop only if there is both a flower to the left and also to the right. Use the simplest
condition you can to express this.

" X900: Jeroo looks left and right


!
You are writing code using a
Your Answer: Feedback
jeroo named jaime . Change 1.0 /
the following if-then… 1.0 1 if (jaime.seesFlower(LEFT) &&
1.0 /
statement's jaime.seesFlower(RIGHT))
Java Jeroocondition so that
conditionals … 1.0
jaime will hop only if 2 {
there... 3   jaime.hop(); Result Behavior
4 }
" X901: Jeroo looks everywhere
! 5
You are writing code using a # With flower on the left
jeroo named jaime . Change 1.0 /
the following if-then… 1.0 # With flower on the right
statement's
Java Jeroocondition so that
conditionals …
jaime will hop if there is
# With no flowers anywhere
a...

" X902: Jeroo looks everywhere …


! # With flowers on left and right
You are writing code using a Check my answer! Reset Next exercise
jeroo named jaime . Change 1.0 /
the following if-then… 1.0
statement's
Java Jeroocondition so that
conditionals …
jaime will hop only if
there...

" X903: Jeroo looks to front and…


!
You are writing code using a
jeroo named jaime . Change 1.0 /
the following if-then… 1.0
statement's
Java Jeroocondition so that
conditionals …
jaime will hop only if
there...

3.1.13. Repeating Actions

In the previous sections, we learned how to use an if-then-else or if-then structure to decide which action to perform. In this section, we will learn how to create a block of statements that can be
executed several times in succession. We do this using a repetition structure (also called a loop), which is one of the fundamental control structures supported by most imperative and object-
oriented programming languages.

A repetition structure (or loop) allows a group of statements to be executed several times in succession. There are three important repetition structures: a loop repeats an action for every object in
a collection of objects, a loop that is controlled by the state of the objects in the program, and a loop that is controlled by a counter (usually a number). In this chapter, we are going to focus on just
one kind of loop, one that is controlled by the state of the objects in the program. This happens to be the most general and most fundamental kind of repetition structure in many programming
languages.

3.1.14. Generic Repetition Structures

There are two major parts to every repetition structure, the body and the controlling condition. These two parts provide a way to classify loops.

The block of statements that can be executed repeatedly is called the body of the loop. Each time that the statements in the body are executed is called a trip (or iteration) through the loop, and
the number of times the body is executed is called the trip count.

The controlling condition is a condition that is checked to determine whether to make a trip through the body or terminate the loop. The controlling condition is rechecked after each trip through
the body of the loop.

One criterion for classifying loops is based on when the controlling condition is checked relative to the first trip through the body. In a pretest loop, the controlling condition is always checked before
the body can be executed for the first time. In a posttest loop, the controlling condition is not checked until after the first trip through the body. In either case, the condition is checked after each trip
through the body to determine whether or not to make another trip.

A second criterion for classifying loops is based on whether a true condition or a false condition leads to a trip through the body. In a while loop, a true condition leads to a trip through the body, but
a false condition terminates the loop. In an until loop, a true condition terminates the loop, but a false condition leads to a trip through the body. The difference between the while and until loops is
summarized in this table:

Combining these two criteria, we can define four broad categories of loops: pretest while, pretest until, posttest while, and posttest until. Few programming languages provide all four of these (most
only provide two, or even one!), but the most common form that is supported in virtually every imperative and object-oriented programming language is the pretest while loop. We’ll focus exclusively
on pretest while loops in the remainder of this chapter.

Since the pretest while loop is the most common repetition structure across imperative and object-oriented languages, we will take a closer look at it.

The figure above shows a generic pretest while loop and uses arrows to show the order in which statements are executed and the condition is checked.

🔄
3.1.15. Java’s Syntax for the While Loop

Java while loop


Share

Watch on

The figure above shows the Java syntax for a pretest while loop in Java. There are three important things to observe about the syntax.

1. The condition must be in parentheses.

2. There is no semicolon after the parentheses containing the condition or after the keyword else.

3. The while structure is not a method, which means that we do not send it as a message to a Jeroo object.

There are three important things to observe about the coding style.

1. Braces are used to define the beginning and end of both the body of the while statement. Always include them.

2. The braces are aligned with the start of the word while.

3. The statements between the braces should be indented (we use 4 spaces).

3.1.15.1. Example (pretest while structure)

Assume that a Jeroo named Kim is not standing on a flower, but there is a line of flowers ahead. Have Kim pick all of those flowers, and stop as soon as there is no flower directly ahead. After
picking all of the flowers, Kim should turn to the left.

while (kim.seesFlower(AHEAD))
{
kim.hop();
kim.pick();
}

kim.turn(LEFT);

3.1.15.2. Self-Check

Practicing While Loops Current score: 3 out of 3

For this question, refer to the following code. Assume you have a jeroo object named kim that does not have a flower ahead of it. Answer

Check Answer
while (kim.seesFlower(AHEAD))
{
kim.hop();
kim.pick(); Need help?
} I'd like a hint

How many times would the following code run?

An error will occur

3.1.16. Syntax Practice 3e: While Loops

Syntax Practice 3e: While Loops 2 X876: Jeroo turns north


100% For this question you writing code for named erin . Change the if statement to a while loop so that
erin will continue turning until erin is facing north. Remember that the while loop condition says
when the action should continue to repeat, so it is the opposite of the condition when the loop should
stop.
" X876: Jeroo turns north
!
For this question you writing
code for named erin . 1.0 / Your Answer: Feedback
Change the if statement to … 1.0
while
Java loop so that
Jeroo erincon…
loops 1 while(!erin.isFacing(NORTH))
will continue turning until 1.0 /
2 {
erin ... 1.0
3   erin.turn(LEFT);
" X904: Jeroo turns toward nort…
!
4 } Result Behavior
5
For this question you writing
code for named erin . 1.0 / # When starting facing EAST
Change the if statement to … 1.0
while
Java loop
CS1so that
Jerooerin
loop…
will continue turning left # When starting facing WEST
until...
# When starting facing SOUTH

# When starting facing NORTH


Check my answer! Reset Next exercise

3.1.17. Programming Practice 3

Programming Practice 3 5 X881: Jeroo lookForFlower()


100% For this question you will write a method that takes a jeroo named paige . Write an if statement to
handle the following logic.

If paige already has a flower, she does nothing.


" X881: Jeroo lookForFlower()
!
For this question you will
If she doesn't have a flower and can see a flower directly ahead, then hop and pick the flower.
write a method that takes a 1.0 /
jeroo named paige . Write… 1.0 Otherwise, if she doesn't have a flower and can see a flower to the left, then turn, hop, and pick the flower.
an
If if statement
paige
Java ...
CS1114 to handle
Jeroo the

following logic. If none of the above apply, paige should do nothing.

" X882: Jeroo turnOrHop()


!
Your Answer: Feedback
For this question you will
write a method that takes a 1 public void lookForFlower(Jeroo paige)
1.0 / 1.0 /
jeroo named ken . Write an… 1.0 2 { 1.0
ifJava
statement to handle
CS1114 Jeroothe …
3  
following logic: If ken has 4   if(paige.hasFlower()) Result Behavior
a... 5   {
6   }
" X883: Jeroo turnNorth()
! # With no flowers anywhere
7
For this question assume you 8 else if(!paige.hasFlower()&&
have access to a jeroo 1.0 / 9         paige.seesFlower(AHEAD)) # With a flower ahead
variable named emily . 1.0
For this question, 10   {
CS1114 aJeroo
jeroo …
Java
could be facing in any 11       paige.hop(); # With flower on the left
direction.... 12       paige.pick();
13   } With flowers both ahead and
" X884: Jeroo pickAll()
#
! 14 on the left
For this question write the 15   else if (!paige.hasFlower()&&          
method pickAll() . Your 1.0 / paige.seesFlower(LEFT))
method is given a jeroo… 1.0 # Already has a flower
16   {
named CS1114 . Write
Java katie Jerooa while
… 17    
loop that will continually hop
18       paige.turn(LEFT);
and...
19       paige.hop();
" X885: Jeroo giveUpAllFlowers() 20       paige.pick();
!
Using both a set of if 21   }
statements and a set of while 1.0 / 22      
loops write code to support… 1.0 23      
the following
Java logic.Jeroo
CS1114 For this… 24      
question assume you have... 25 }
26

Check my answer! Reset Next exercise

3.1.18. Check Your Understanding

Practicing Full Chapter Reading Quiz Current score: 12 out of 12

Which of these is the NOT operator (logical negation)? Answer

Check Answer
&&

!
Need help?
||
I'd like a hint

!!

Selected content adapted from:


Java Java Java, Object-Oriented Problem Solving 3rd edition by R. Morelli and R. Walde, licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).
Think Java: How to Think Like a Computer Scientist version 6.1.3 by Allen B. Downey and Chris Mayfield, licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-
NC-SA 4.0).

Contact Us | © Copyright 2021 by OpenDSA Project Contributors and distributed under an MIT license. Last updated on Aug 20, 2022. Created using Sphinx 2.4.4.

"Previous Next#

You might also like