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

This is an if statement how to convert it to swich statement if (academicYear <=

ID: 3585973 • Letter: T

Question

This is an if statement how to convert it to swich statement

if (academicYear <=5 && academicYear >=1)

{

if (academicYear == 5)

{

System.out.println("I am a " + YEAR5 + " student. ");

}

else if (academicYear == 4)

{

System.out.println("I am a " + YEAR4 + " student. ");

}

else if (academicYear == 3)

{

System.out.println("I am a " + YEAR3 + " student. ");

}

else if (academicYear == 2)

{

System.out.println("I am a " + YEAR2 + " student. ");

}

else if (academicYear == 1)

{

System.out.println("I am a " + YEAR1 + " student. ");

}

else

{

System.out.println(academicYear + " is not a vaild year.");

System.out.println("Please enter a valid academic year.");

System.out.println("Quitting the program.!!!!");

System.exit(0);

}

}

Explanation / Answer

Answer:

switch(academicYear) {

case 5:

System.out.println("I am a " + YEAR5 + " student. ");

break;

case 4:

System.out.println("I am a " + YEAR4 + " student. ");

break;

case 3:

System.out.println("I am a " + YEAR3 + " student. ");

break;

case 2:

System.out.println("I am a " + YEAR2 + " student. ");

break;

case 1:

System.out.println("I am a " + YEAR1 + " student. ");

break;

default:

System.out.println(academicYear + " is not a vaild year.");

System.out.println("Please enter a valid academic year.");

System.out.println("Quitting the program.!!!!");

System.exit(0);

}

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