Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

variable might not have been initialized??

807601May 11 2008 — edited May 12 2008
I'm still learning Java, so be easy on me :) The book I'm using to teach me wants me to make a program that allows you to input a students name and score. Then the program will give an output of the persons name and assign them a letter grade for the score.

here is what i came up with:

import javax.swing.*;
import java.util.*;

public class gradehelper
{
public static void main(String[] args)
{
String name;
char grade;

name = JOptionPane.showInputDialog("Enter name: ");

String n1String;
n1String = JOptionPane.showInputDialog("Enter your score:");

int score;
score = Integer.parseInt(n1String);


if (score >= 90)
grade = 'A';
else if (score >= 80)
grade = 'B';
else if (score >= 70)
grade = 'C';
else if (score >= 60)
grade = 'D';
else if (score < 60)
grade = 'F';
else
System.out.println("Invalid Score");

System.out.println("Student: " + name);
System.out.println("Grade: " + grade);

System.exit(0);
}
}


I'm sure this looks sloppy, but I am trying really hard! I keep getting 'variable grade might not have been initialized' for line 34.

Any tips?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 9 2008
Added on May 11 2008
8 comments
887 views