title: Find max value in java from file input
body: <p>I'm new to Java and I am trying to write a program that asks the user to input the name of a txt file containing only numbers, and the program will output the sum, average, max, and min of the numbers in the file. I have written most of the program, however I am stuck trying to find the max and min of the values. Any information you can give would be helpful, and if I was not clear enough I can try to elaborate. My code so far is: </p>
  
  <pre><code>public class NumberFile{
      public static void main(String[] args){
  
        boolean goodName = false;
        int currentNumber, sum = 0, numberCount=0;
        Scanner numberFile = null;
        FileReader infile; 
  
        Scanner input = new Scanner(System.in);
        System.out.println("Please enter the name of the file you wish to import: ");
        String fileName = input.nextLine();
  
  
  
        while (!goodName){
          try{
            infile = new FileReader(fileName);
            numberFile = new Scanner(infile);
            goodName = true;
          }
          catch (IOException e){
            System.out.println("invalid file name, please enter another name");
            fileName = input.nextLine();
          }
        }
        while (numberFile.hasNextInt()){
          currentNumber = numberFile.nextInt();
          sum+=currentNumber;
          numberCount++;
        }
        System.out.println("The sum of the numbers is " +sum);
  
        System.out.println("The average of the numbers is " + ((double) sum)/numberCount);
  
  
  
      } // end main
  } // end class
  </code></pre>