Rewrite the following program segment using switch case: char code; if(code==’B’ || code==’b’) System.out.println(“Bank Manager”); if(code==’C’ || code==’c’) System.out.println(“Charted Accountant”); if(code==’D’ || code==’d’) System.out.println(“Engineer”); if(code==’M’ || code==’m’) System.out.println(“Minister”)
char code;
switch(code)
{
case ‘B’:
case ‘b’:System.out.println(“Bank Manager”);
break; case’C’:
case’c’:System.out.println(“Charted Accountant”);
break;
case’E’:
case’e’:System.out.println(“Engineer”);
break; case’M’: case’m’:System.out.println(“Minister”);
break;
}
switch(code)
{
case ‘B’:
case ‘b’:System.out.println(“Bank Manager”);
break; case’C’:
case’c’:System.out.println(“Charted Accountant”);
break;
case’E’:
case’e’:System.out.println(“Engineer”);
break; case’M’: case’m’:System.out.println(“Minister”);
break;
}
No comments: