CountIntegers1 - Scanner sc = new Scanner (System.in); //...

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

View Full Document Right Arrow Icon
//******************************************************************** // CountIntegers1.java Author: Lewis and Loftus // // Solution to Programming Project 6.1 //******************************************************************** / import java.util.Scanner; i public class CountIntegers1 { public static void main (String [] args) { int [] occurrences = new int [51]; System.out.println ("Enter integers in the range 0-50."); 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 >= 0 && entered <= 50) { // increment the appropriate counter occurrences [entered] ++; // 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 = 0; check <= 50; check++) if (occurrences [check] >= 1) System.out.println (check + "\t" + occurrences [check]); } }...
View Full Document

Ask a homework question - tutors are online