(ii) if-else-if construct into switch case
if(var==1)
System.out.println("Distinction");
else if(var==2)
System.out.println("First Division");
else if(var==3)
System.out.println("Second Division");
else
System.out.println("invalid");
Answers
Answered by
17
Program:
switch(var){
Case 1: System.out.println("Distinction");
break;
Casa 2: System.out.println("First Division");
break;
Case 3: System.out.println("Second Division");
break;
default: System.out.println("Invalid");
break;
}
Explanation:
When ever you use a use a switch-case you have to write"break" for every case you write, because if that case is true it will print the following code and checks whether break is there or not if there it will break the while loop if not it will go to next true case and prints those lines too
-----Hope you got what you wanted ( give brainliest if you like my answer) :)
Similar questions
Physics,
6 months ago
Math,
6 months ago
Political Science,
11 months ago
English,
11 months ago
Science,
1 year ago