FindRange

FindRange - print("? "); int x=readInt(); i...

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

View Full Document Right Arrow Icon
/* * File: FindRange.java * Name: * Section Leader: * -------------------- * This file is the starter file for the FindRange problem. */ import acm.program.*; i public class FindRange extends ConsoleProgram { p private static final int SENTINEL=0; p public void run() { p println("This program finds the largest and smallest numbers.");
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: print("? "); int x=readInt(); i if(x==SENTINEL) {println("No values have been entered.");return;} int smallest=x; int largest=x; while(x!=SENTINEL){ if(x>largest) largest=x; if(x<smallest) smallest=x; print("? "); x=readInt(); } println("smallest: "+smallest); println("largest: "+largest); } }...
View Full Document

This note was uploaded on 10/25/2010 for the course CS 106A at Stanford.

Ask a homework question - tutors are online