CountIntegers2 - Scanner sc = new Scanner(System.in read...

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

View Full Document Right Arrow Icon
//******************************************************************** // CountIntegers2.java Author: Lewis and Loftus // // Solution to Programming Project 6.2 //******************************************************************** / import java.util.Scanner; i public class CountIntegers2 { public static void main (String [] args) { int [] occurrences = new int [51]; System.out.println ("Enter integers in the range -25 to 25."); System.out.print ("Signal end of list with a "); System.out.println ("number outside the 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); // read all the integers int entered = sc.nextInt (); while (entered >= -25 && entered <= 25) { // increment the appropriate counter occurrences [entered + 25] ++; // read the next value entered = sc.nextInt (); } // report all integers that were entered one or more times // System.out.println ("Number\tTimes"); for (int check = -25; check <= 25; check++) if (occurrences [check+25] >= 1) System.out.println (check + "\t" + occurrences [check+25]); } }...
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