Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 {
- /* SENTINEL = 0 */
- private static final int SENTINEL=0;
- /* this program will generte a list of integers given by the user, and find the smallest and largest integers */
- public void run() {
- int smallestNumber=1000000000;
- int largestNumber=-1000000000;
- while (true){
- int Int=readInt("?:");
- if (Int==SENTINEL) break;
- if (Int>largestNumber){
- largestNumber=Int;
- }
- if (Int<smallestNumber){
- smallestNumber=Int;
- }
- }
- if (largestNumber==-1000000000){
- if (smallestNumber==1000000000){
- println("No solution!");
- }
- } else {
- println("The largest integer is:"+largestNumber+".");
- println("The smallest integer is:"+smallestNumber+".");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement