Question: This program inputs letter grades for 20 students in the class then prints out stars representing the number of students who received each grade. For
This program inputs letter grades for 20 students in the class then prints out stars representing the number of students who received each grade. For example if there were 3 A's, 2 B's, 10 C's, 4 D's and 1 F the output would be
A: *** B: ** C: ********** D: **** F: *
import java.util.Scanner;
public class Number2 {
public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Enter 20 letter grades"); String grade; int numA=0, numB=0, numC=0, numD=0, numF=0; for (int i=0; i<20; i++) { grade=keyboard.next(); grade=grade.toUpperCase(); grade=grade.substring(0,1); switch(grade) {case "A": numA++;break; case "B":numB++;break; case "C":numC++;break; case "D":numD++;break; case "F":numF++;break; } } printStars(numA, numB, numC, numD, numF); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
