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

1.Assume that size is an int variable which is storing a value between 0 and 90

ID: 3596817 • Letter: 1

Question


1.Assume that size is an int variable which is storing a value between 0 and 90 inclusive.

a. Assume that the “else” part on if-else statements is no longer valid in Java. Convert the following nested if-else structure to a series of if statements presented in the partially-completed Java code which produce the same output.

b. Convert the following nested if-else to a switch statement presented in the partially completed Java code which produces the same output.

if (size > 59)

    System.out.println (“Big”);

else

    if (size > 29)

        System.out.println(“Average”);

    else

         System.out.println(“Small”);

Explanation / Answer

a)

if(size > 59)

System.out.println (“Big”);

if(size > 29 && size <= 59)

System.out.println(“Average”);

if(size <= 29)

System.out.println(“Small”);

b)

int range = (size) / 30 ;

switch (range) {

case 0:

System.out.println ("Small");

break;

case 1:

System.out.println ("Average");

break;

default:

System.out.println ("Big");

break;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote