HomeToddlersHelp with programming in java!?
Posted in Toddlers on 12th November 2011

Help with programming in java!?
How would you convert the following from an if statement into a case statement?

if (age <= 2) System.out.println("toddler"); else if (age <= 10) System.out.println("child"); else if (age <13) System.out.println("tween"); else if (age < 20) System.out.println("teenager"); else System.out.println("adult"); Thanks Best answer(s):

Answer by sam
switch(age){
case 0:
case 1:
case 2:
System.out.println(“toddler”);
break;
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
System.out.println(“child”);
break;
case 11:
case 12:
System.out.println(“tween”);
break;
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
System.out.println(“teenager”);
break;
default:
System.out.println(“adult”);
break;
}

Answer by Sergey Vaulin
whats wrong with “IF” operator ? Switch will be not good-looking…

switch (age) {
case 1: case 2:
System.out.println(“toddler”);
break;

case 3: case 4: case 5: … etc
System.out.println(“child”);
break;

….

default:
System.out.println(“adult”);
}

Related Post for The Finest Academic Apps for Youngsters

Encourage Mindfulness for Kids
7 Wonderful Causes to Introduce Music in Early Childhood Training
Learn how to Encourage Artistic Downside-Fixing in Youngsters
The right way to Assist Your Little one Get a Good Night time’s Sleep
The Finest Academic Apps for Youngsters