Anyone to help have tried a lot but can't get the 75+ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

12th May 2022, 1:25 AM
GEORGE EGYIR MAYNE
GEORGE EGYIR MAYNE - avatar
5 Answers
+ 1
switch(expression) { case 1: // code block break; case 2: // code block break; default: // code block }
12th May 2022, 2:00 AM
Chris Coder
Chris Coder - avatar
+ 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); } }
12th May 2022, 10:21 AM
Thineshan Panchalingam
Thineshan Panchalingam - avatar
0
Show your code attempt
12th May 2022, 2:01 AM
Chris Coder
Chris Coder - avatar
0
How will the code block be
12th May 2022, 2:02 AM
GEORGE EGYIR MAYNE
GEORGE EGYIR MAYNE - avatar
12th May 2022, 2:03 AM
GEORGE EGYIR MAYNE
GEORGE EGYIR MAYNE - avatar