// Yazzy Latif // 7/27/2020 // CSE142 // TA: Grace Hopper // Reads an input file and reports the real numbers read in (skipping and reporting non-number // tokens) and prints out the minimum and maximum values read. import java.io.*; // for file processing import java.util.*; // scanner public class FindMinAndMax { public static void main(String[] args) throws FileNotFoundException { File f = new File("data.txt"); Scanner input = new Scanner(f); // if i was given a guarantee of the bounds // use that as min and max double firstVal = input.nextDouble(); System.out.println("next double was " + firstVal); double min = firstVal; double max = firstVal; //for (int i = 1; i <= 4; i++) { while (input.hasNext()) { if (input.hasNextDouble()) { double nextVal = input.nextDouble(); System.out.println("next double was " + nextVal); min = Math.min(min, nextVal); max = Math.max(max, nextVal); } else { // throw away this token // we don't need to print it out, if we want we could // just have the line: // input.next() System.out.println("bad token was " + input.next()); } } System.out.println("minimum was " + min + ", and maximum was " + max); } }