title: Calculating the average number in a nesting loop Java
body: <p>does anyone knows how to calculate the average in a loop. Every time I calculated the average I received 0 or 1.   I know that I need use average = (sum) / (salary_annually);  but I can't get it to work. Thanks in advance.  </p>
  
  <pre><code> import java.util.Scanner;
  
  public class midterm 
  {
  public static void main(String args[]) 
  {
      Scanner kb = new Scanner(System.in);
  
      int max = Integer.MIN_VALUE;
      int min = Integer.MAX_VALUE;
      int sum = 0;
      int average=0;
      int count = 0;
      int salary_annually = 0;
  
      for(int employee =1; employee &lt;= 2; employee++)
      {
      System.out.println("Employee: " + employee);
  
           for(int year=1; year &lt;= 2; year++)
           {
  
              System.out.println("Please Enter the Salary for Year: "  + year);
                salary_annually = kb.nextInt();
  
                            sum += salary_annually  ;
                if (min &gt;= salary_annually) 
                { 
                       min = salary_annually;
                } 
               if (max &lt;=salary_annually) 
               { 
                 max = salary_annually;
                } 
  
              average = (sum) / (salary_annually); 
  
  
           }
  
            System.out.println("The average is " + average);
         System.out.println("The higher number  " + max);
         System.out.println("The the lowest number " + min);
       }
  
     }
    }
  </code></pre>