// This program processes a file full of midterm scores and // outputs a text histogram of how many students got each score. import java.io.*; // for File import java.util.*; // for Scanner public class Midterm { public static void main(String[] args) throws FileNotFoundException { int[] counts = new int[101]; // 0 - 100 Scanner input = new Scanner(new File("scores.txt")); while (input.hasNextInt()) { int studentScore = input.nextInt(); counts[studentScore]++; } for (int i = 0; i < counts.length; i++) { if (counts[i] > 0) { System.out.print(i + ": "); for (int j = 0; j < counts[i]; j++) { System.out.print("*"); } System.out.println(); } } } }