Posted on Leave a comment solution – Assignment 2

[code lang=”java”]
* File:
* Name:
* Section Leader:
* ——————–
* This file is the starter file for the FindRange problem.

import acm.program.*;

public class FindRange extends ConsoleProgram {
private static final int SENTINEL = 0;

public void run() {
//the smallest number
int smallest = 0;

//the largest
int largest = 0;
println("The program finds the largest and smallest numbers.");

//get the first number
int number = readInt("? ");
//if there is only one number – make it the smallest and th
// the largest

//loop and a half for the second number
//keep looping until the sentinel is given
//get the second digit
int number1 = readInt("? ");

// breaking out of the loop

//find the smallest number
if(number1<smallest ){

//find the largest number

//if the first number is a 0
// else print the smallest and largest
if(number == SENTINEL){
println("Please enter a number not 0.");
} else {
println("smallest: "+smallest);
println("largest: "+largest);


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.