I m new.I am not getting any result for

Number of A
Number of B
Numbers of C
Number of D
number of F
for A,B,C,D,F i always get 0.

import java.util.Scanner;
public class ExamScores1
{
	public static void main (String[]args)
	{
		String a;
		int count= 0;

		int grade=0;     // you declare grade = 0 here
		int A=0;
		int B=0;
		int C=0;
		int D=0;
		int F=0;




		Scanner scan = new Scanner (System.in);
		System.out.println("Enter your exam grades");


		a=scan.nextLine();
		int len=a.length ();

		for (int i=0; i< len; i++)
		{
			if (a.charAt (i) ==' '){
				count--;
			}else {
				count++;

			}
		}


// grade is still == 0 here

		if (grade > 90 && grade <= 100) {
			grade= 'A';
			A=A+1;
			count++;
		} else if (grade > 80 && grade <= 89) {
			grade= 'B';
			B=B+1;
			count++;

		} else if (grade > 70 && grade <= 79) {
			grade= 'C';
			C=C+1;
			count++;

		} else if (grade > 60 && grade <= 69) {
			grade= 'D';
			D=D+1;
			count++;
		} else if (grade> 0 && grade <= 59) {
			grade= 'F';
			F=F+1;
			count++;
		}
		System.out.println("total no of grades=" + count);
		System.out.println("Number of A=" + A);
		System.out.println("Number of B=" + B);
		System.out.println("Number of C=" + C);
		System.out.println("Number of D=" + D);
		System.out.println("Number of F=" + F);
	}
}

Recommended Answers

All 5 Replies

I don't understand, you don't assign a value to grade after grade = 0,
How can you expect it to ever enter any of the if statements?

And why are you assigning character values to an int object, "grade = 'A'"?

This is the same code you posted before, with the same problems. You are not assigning a value to grade after initializing it, as already stated. Also, with what you have you are only going to be able to have a maximum of one grade entered.

I don't understand the necessity of lines 26-34, if anything it will mess up your count, because you get the number of grades, but increment it again later in your if construct. Also, you must assign a variable to 'grade' after initalization (as has been said already) and you can't assign strings/chars to an object of type int.

sigh ...
how many times are you going to re-post this same code with the same errors in it, ignoring the help and answers you are provided with? just check the other thread(s) in which you ask help for this code, and you'll see you should have finished your work quite some time ago.

Member Avatar for hfx642

I'm sorry, but... LOL.
(I agree with stultuske SO much!)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.