Assignment2_FindRange

来源:互联网 发布:linux 挂载大硬盘 编辑:程序博客网 时间:2024/06/05 14:48
/*
 * 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 {


/* define your constants here. (like your SENTINEL value) */


public void run() {
// You fill this in
println("This program finds the largest and smallest numbers.");
int a = readInt("?");
int min = a, max = a;
while (a != 0) {
if (a > max)
max = a;
if (a < min)
min = a;
a = readInt("?");
}
println("smallest: " + min);
println("largest: " + max);
}


}
原创粉丝点击