Question: Can I adopt a pet? Given a variable personAge, code a conditional statement that will allow one of the following to be printed: You can

Can I adopt a pet?

Given a variable personAge, code a conditional statement that will allow one of the following to be printed:

"You can adopt a pet!" if you are at least 18 years old.

"You are not old enough to adopt a pet!" otherwise.

Assume that you have to be at least 18 years old to adopt a pet!

Solution

Reset

Java

if (canAdoptPet) {

Sample Test Case #1

10

Execute code

STDOUT

CodingQuestion.java:17: error: cannot find symbol

CanAdoptPet = true;

^

symbol: variable CanAdoptPet

location: class CodingQuestion

CodingQuestion.java:19: error: cannot find symbol

CanAdoptPet = false;

^

symbol: variable CanAdoptPet

location: class CodingQuestion

2 errors

Expected STDOUT

You are not old enough to adopt a pet!


Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!