Error in my Java code, Grade Book? -
i new coding, , taking online course learn java. had assignment assign (string) letter grades based on (int) grades. use tester program, i'm not savvy on how write such programs yet.
is there error in code:
string lettergrade = "f"; grade = grade; while (grade >= 90) { lettergrade = "a"; } if (grade >79) { lettergrade = "b"; } else if (grade > 69) { lettergrade = "c"; } else if (grade >59) { lettergrade = "d"; } return lettergrade;
as pointed out in comments, think use of while here. should try understand first each statement means when code. anyway, should use 'if' instead of 'while' rest of stuff seems correct. if use 'while' , case seems true stuck in loop forever.
and testing program not difficult use different test cases @ beginning put grade = 55; // random test case numbers.
i tempted give solution not gonna because simple enough.
Comments
Post a Comment