Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java: Consider the code below. Assume num is an integer and has already been ass

ID: 3841959 • Letter: J

Question

Java: Consider the code below. Assume num is an integer and has already
been assigned a value. Fix the errors in the code, if any, so it
prints the appropriate messages for each condition. As it is
written below, for what range of values of num will the last print
statement (the one that prints “This number is greater than 100.”)
be called?
if (num < 30)
if (num < 20)
System.out.println (“This number is less than 20.”);
else if (num < 100)
System.out.println (“This number is greater than 30 and ”
+ “less than 100.”);
else
System.out.println (“This number is greater than 100.”);

Explanation / Answer

if (num < 30)
if (num < 20)
System.out.println (“This number is less than 20.”);
else if (num < 100)
System.out.println (“This number is greater than 20 and ”

+ “less than 100.”);   /* change the value 30 to 20 because if the value is between 20 to 30 it will show it is greater *than 30 which is false*/

else
System.out.println (“This number is greater than 100.”);

The range of values of num will the last print statement (the one that prints “This number is greater than 100.”) is 101 - infinity.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote