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

Modify the following source code so that redundancy and errors do not occur. Rat

ID: 3738424 • Letter: M

Question

Modify the following source code so that redundancy and errors do not occur. Rather than relying on a nested if/else, use ranges for your conditions.

Scanner console = new Scanner(System.in);

System.out.print("What is your age (in years)? ");

int age = console.nextInt();

if (age > 18) {

System.out.println("You're an adult!");

}

if (age <= 18) {

System.out.println("You're a teenager!");

}

if (age <=12) {

System.out.println("You're a tween!");

}

if (age <= 9) {

System.out.println("You're ready for school!");

}

if (age <= 5) {

System.out.println("You're a preschooler!");

}

if (age <= 2) {

System.out.println("You're a toddler!");

}

if (age < 1) {

System.out.println("You're one smart baby!");

}

Explanation / Answer

here is the answer....

===============================================================

Scanner console = new Scanner(System.in);

System.out.print("What is your age (in years)? ");

int age = console.nextInt();

if (age > 18) {

System.out.println("You're an adult!");

}

if (age > 12 && age <= 18) {

System.out.println("You're a teenager!");

}

if (age > 9 && age <=12) {

System.out.println("You're a tween!");

}

if (age > 5 && age <= 9) {

System.out.println("You're ready for school!");

}

if (age > 2 && age <= 5) {

System.out.println("You're a preschooler!");

}

if (age>1 && age <= 2) {

System.out.println("You're a toddler!");

}

if (age>0 && age < 1) {

System.out.println("You're one smart baby!");

}

================================================================

Kindly Check and Verrify Thanks..!!!

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