First of; I am very new to programming...
What i am trying to do is have a simple program which calculates your grade based on your marks, here is what i have right now:
class Grade {
public static void main(String[]args){
char grade;
int marks = 92;
if(marks<60)
grade = 'F' ;
else if(marks>61 && marks<69)
grade = 'D';
else if(marks>70 && marks<79)
grade = 'C';
else if(marks>80 && marks<89)
grade = 'B';
else if(marks>90 && marks<99)
grade = 'A';
else
System.out.println("Bogus Grade");
System.out.println("Your grade is " + grade);
}
}
(For now i'm just specifying the grade in the code, and will work on user input later)
While trying to compile the code I get this error:
Grade.Java:30: error: variable grade might not have been initialized
System.out.println("Your grade is" + grade);
^
marksto60and you will see the problem. Thegradevariable needs to be set likechar grade = 'I';or something similar. Then fix your if/else blocks to handle the grades (e.g.<=instead of<).