[key] csa u4l7 nested if statements extra practice
[key] csa u4l7 nested if statements extra practice
System.out.print("Y");
}
if (c < 10) {
if (b > 10) {
System.out.print("Y");
}
else {
System.out.print("Z");
}
}
}
A. XY
B. XYZ
C. Y
D. YY
E. Z
1
AP Exam Prep
Consider the following code segment. Assume num is a properly declared and initialized int variable.
if (num > 0) {
if (num % 2 != 0) {
System.out.println("A");
}
else {
System.out.println("B");
}
}
Which of the following best describes the result of executing the code segment?
A. When num is a negative odd integer, "B" is printed; otherwise, "A" is printed.
B. When num is a negative even integer, "B" is printed; otherwise, nothing is printed.
C. When num is a positive even integer, "A" is printed; otherwise, "B" is printed.
D. When num is a positive even integer, "A" is printed; when num is a positive odd integer, "B" is
printed; otherwise, nothing is printed.
E. When num is a positive odd integer, "A" is printed; when num is a positive even integer, "B" is
printed; otherwise, nothing is printed.
2
Extra Practice
Do This: A citizen science project is looking to inventory all of the trees in New York City. They would like to
allow citizens to use an app to inventory trees based on species and location. They do not want two people to
enter the same tree into their system and will determine whether this has occurred by comparing the latitude
and longitude. Write a class called Tree with the following specifications:
Instance Variables:
● species - String
● latitude - double
● longitude - double
● latitude
● longitude
An equals() method which compares two trees based on their latitude and longitude.
3
}
}