find range code

find range code - ); do { enteredValue = readInt(...

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

View Full Document Right Arrow Icon
/* * File: FindRange.java * -------------------- * This program is a stub for the FindRange problem, which finds the * smallest and largest values in a list of integers. */ import acm.program.*; public class FindRange extends ConsoleProgram { public void run() { // This program finds the smallest and largest integers in a list. while ( true ){ int Largest = 0, Smallest = 0; int enteredValue= stopper ; println( "This program finds the smallest and largest integers in a list. " + "Enter values, one per line, using a " + stopper + " to signal the end of the list."
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ); do { enteredValue = readInt( "?" ); if (enteredValue != stopper ){ if (enteredValue > Largest) Largest = enteredValue; if (enteredValue < Smallest || Smallest == stopper ) Smallest = enteredValue; } } while (enteredValue != stopper ); if (Largest == Smallest && Largest == stopper ){ println( "No values have been entered." ); } else { println( "Smallest value is " + Smallest); println( "Largest value is " + Largest); } println(); } } private static final int stopper = 0; }...
View Full Document

Ask a homework question - tutors are online