title: Calculating average of grades in Java
body: <p>I want to create a program where I can input numbers and grades and the computer will calculate the average of the passing ones only but if the numerator or dinomenator was zero what will happened how can I fix this?</p>
  
  <pre><code>public class Grades {
  
      public static void main (String[] args) {
          double grade1, grade2, grade3, avg, sum=0;
          int counter = 0;
          Scanner input = new Scanner(System.in);
          System.out.println("Enter your first Grade");
          grade1 = input.nextDouble();
          if (grade1 &gt;= 90)
          {
              System.out.println("excellent");
              counter++;
              sum += grade1;
          }
          else if (grade1 &lt; 90 &amp;&amp; grade1 &gt;= 70)
          {
              System.out.println("very good");
              counter++;
              sum += grade1;
          }
          else if (grade1 &lt; 70 &amp;&amp; grade1 &gt;= 60)
          {
              System.out.println("fair");
              counter++;
              sum += grade1;
          }
          else if (grade1 &lt; 60)
          {
              System.out.println("you fail");
          }
          System.out.println("Enter your second Grade");
          grade2 = input.nextDouble();
          if (grade2 &gt;= 90)
          {
              System.out.println("excellent");
              counter++;
              sum += grade2;
          }
          else if (grade2 &lt; 90 &amp;&amp; grade2 &gt;= 70)
          {
              System.out.println("very good");
              counter++;
              sum += grade2;
          }
          else if (grade2 &lt; 70 &amp;&amp; grade2 &gt;= 60)
          {
              System.out.println("fair");
              counter++;
              sum += grade2;
          }
          else if (grade2 &lt; 60)
              System.out.println("you fail");
          System.out.println("Enter your third Grade");
          grade3 = input.nextDouble();
          if (grade3 &gt;= 90)
          {
              System.out.println("excellent");
              counter++;
              sum += grade3;
          }
          else if (grade3 &lt; 90 &amp;&amp; grade3 &gt;= 70)
          {
              System.out.println("very good");
              counter++;
              sum += grade3;
          }
          else if (grade3 &lt; 70 &amp;&amp; grade3 &gt;= 60)
          {
              System.out.println("fair");
              counter++;
              sum += grade3;
          }
          else if (grade3 &lt; 60)
              System.out.println("you fail");
          avg=sum/counter;
          System.out.println("your average is : "+avg);
  
  
      }
  }
  </code></pre>