Rewrite the following set of if-else statement in terms of switch case statement for the
following code fragment:
int code;
code=sc.nextlnt();
if (code==1)
System.out.print(" Accountant");
else
if (code==5 || code==6)
System.out.print("Grade IV");
else
if (code==3)
System.out.print("Financial Advisor");
Answers
Answered by
18
Hey there!
The program using switch case statement would be:
int code;
code=sc.nextInt();
switch(code)
{
case 1:
System.out.print("Accountant");
break;
case 5:
case 6:
System.out.print("Grade IV");
break;
case 3:
System.out.print("Financial Advisor");
}
Hope It Helps You!
Similar questions
Biology,
7 months ago
Computer Science,
7 months ago
English,
7 months ago
Math,
1 year ago
Physics,
1 year ago