Can any one this make else if to switch | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can any one this make else if to switch

Hi guys, Can any one make this if else condition to switch case, I tried but didn't find solution. private String findGrade(int score) { String grade = ""; if (score >= 85) { grade = "HD"; } else if (score > 75 && score <= 84) { grade = "D"; } else if (score > 65 && score <= 74) { grade = "C"; } else if (score > 55 && score <= 64) { grade = "P"; } else { grade = "F"; } return grade; } Thanks...

27th May 2017, 11:38 AM
Sai kumar
Sai kumar - avatar
1 Answer
+ 1
String grade = ""; switch((score - 5) / 10) { case 9: case 8: grade = "HD"; break; case 7: grade = "D"; break; case 6: grade = "C"; break; case 5: grade = "P"; break; default: grade = "F"; } return grade; Maybe this will work.
27th May 2017, 3:03 PM
OrbitHv [Inactive]
OrbitHv [Inactive] - avatar