+ 1
Anyone to help have tried a lot but can't get the 75+
@Karl Scores 80+=A 75+=B+ 70+=B 65+=C+ 60+=C 55+=D+ 50+=D <50=E Converting if-else-condition to switch case for the scores
5 Antworten
+ 1
switch(expression) {
case 1:
// code block
break;
case 2:
// code block
break;
default:
// code block
}
+ 1
I tried to think your way
------------------------------
import java.util.Scanner;
class Test{
public static String getResult(int marks){
if(marks>100 || marks<0){
return "invalid marks";
}
String grade = null;
int in = marks/5;
switch(in){
case 20:
case 19:
case 18:
case 17:
case 16: grade = "A"; break;
case 15: grade = "B+"; break;
case 14: grade = "B"; break;
case 13: grade = "C+"; break;
case 12: grade = "C"; break;
case 11: grade = "D+"; break;
case 10: grade = "D"; break;
default: grade = "E";
}
return grade;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the Scores");
int scores = input.nextInt();
String res = getResult(scores);
System.out.println(res);
}
}
0
Show your code attempt
0
How will the code block be