0

what’s wrong with my code?

public class Program { public static void main(String[] args) { if(score >= 60) System.out.println("D"); else if(score >= 70) System.out.println("C"); else if(score >= 80) System.out.println("B"); else if(score >= 90) System.out.println("A"); else System.out.println("F"); } }

7th Oct 2020, 8:54 PM
Blue Monster
Blue Monster - avatar
1 Answer
+ 3
in addition to the problems with the score variable mentioned by codemonkey, the logic is upside-down. As the code is currently shown, if score is 90 then it wrongly prints 'D' because the first conditional tests whether 90 is greater than or equal to 60, which is true. To fix the logic, check for the highest grade level first (90), and then on down to the lowest grade level last (60).
8th Oct 2020, 12:00 AM
Brian
Brian - avatar