So i posted several days ago about an adding grades to an array, which i managed to figure out. This is the code I currently have.

public class Grades {
	
	public static void main (String[] args)
	{
		float result = 0;
		Scanner scan = new Scanner(System.in);
		int count = 0;
		
		float[] grades = new float[100];
		
		for (int i = 0; i < grades.length; i++) {
			System.out.print("Enter a grade between 0.0 - 100.0 (enter -1 to quit): ");
			grades[i] = scan.nextFloat();
			if(grades[i] == -1)break;
			result = result + grades[i];
			count++;
	
		}
		System.out.println("Average of Grades: " + result / count);
		
		System.out.println("Histogram Of Grades");
		System.out.println("-------------------");
		
}
}

The problem I now have is that I need to add a * if the grades fall under that number range (ex.: 0-59: **, 60-69: ****) and so on for the grades up to 100. Im having trouble on how to know that the numbers fit then adding a star. Any help would be greatly appreciated, even just a start in the right direction.

print "0-59: "
loop through the grades array
  if grades[i] >0 and <=59 print "*"
print a newline

You can repeat this for each line of the histogram or you can get smart and work out how to (a) do it inside another loop or (b) put that code in a method and call it once for each line.

You can also do:

if(grades[i] < 60)
// print 1 star
else if(grades[i] < 70)
// print 2 stars
// etc etc ...
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.