/**
** Author: Walid Bahsow.
** E-mail: wabsnet@yahoo.com
** Thursday 20th of March, 2003
**/
/* This is a simple program which reads numbers from a file,
finds the largest one and prints it into another file.
*/
import java.io.*;
class MaxNum {
static StreamTokenizer in; // input file
static PrintWriter out; // output file
public static void main(String[] args)throws IOException{
// A call for the printMax method and giving it
// the maximum number which is returned by the metho findMax.
printMax(findMax());
} // end main
// Finds the largest number in the file maxnum.in and
returns it.
static int findMax()throws IOException {
in = new StreamTokenizer(new
FileReader("maxnum.in"));
int max = Integer.MIN_VALUE;
while (in.nextToken() != in.TT_EOF) {
if ((int)
in.nval > max) {
max = (int) in.nval;
}
}
return max;
}
// Prints the integer passed to it in the file maxnum.out
static void printMax(int x)throws IOException {
out = new PrintWriter (new FileWriter
("maxnum.out"));
out.println("The largest number is:
"+x);
out.close();
}
} // end class MaxNum