Histogram - Scanner sc = new Scanner (System.in); int...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // Histogram.java Author: Lewis and Loftus // // Solution to Programming Project 6.4 //******************************************************************** / import java.util.Scanner; i public class Histogram { public static void main (String [] args) { int[] ranges = new int [10]; int box; System.out.println ("Enter some numbers between 1 and 100."); System.out.print ("Signal the end by entering "); System.out.println ("a number out of that range.");
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Scanner sc = new Scanner (System.in); int entered = sc.nextInt (); while (entered >= 1 && entered <= 100) { box = (entered - 1) / 10; ranges[box] ++; entered = sc.nextInt (); } // print histogram for (box = 0; box < 10; box++) { System.out.print ((10 * box + 1) + "-"); System.out.print ((10 * box + 10) + "\t|"); for (int count = 0; count < ranges[box]; count++) System.out.print ("*"); System.out.println (); } } }...
View Full Document

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Ask a homework question - tutors are online