Hey there, looking for help, we are building a grade calculator where we are trying to used a method within a method (code will explain) however i keep getting this variable not initialized and i dont know why heres my code:
import java.util.Scanner; public class StudentGradesWeek7 { public static void main(String[] args) { String input = ""; while (!input.equals("q")) { Scanner in = new Scanner(System.in); System.out.println("Enter student grade percentage or 'q' to exit:"); input = in.nextLine(); if (!input.equals("q")) { int inputMark = Integer.parseInt(input); char g = getGrade(inputMark); System.out.println("The students grade is:" + g); } } } private static char getGrade(int mark) { char grade; if (mark >= 70) { grade = 'A'; } else if (mark >= 65) { grade = 'B'; } else if (mark >= 55) { grade = 'C'; } else if (mark >= 45) { grade = 'D'; } else if (mark >= 44) { grade = 'F'; } return grade; } }
The program is supposed to ask what percentage grade the student received then issue them the grade, it will then ask again or ask them to enter q for the program to exit, any help is much appreciated!!
Thank you, Nathan
EDIT: its the last line: return grade; which is giving me the problem