1 import javax.swing.*;
 2 import java.util.Scanner; 
 3 
 4 public class Average {
 5 
 6     /**
 7      * @param args the command line arguments
 8      */
 9     public static void main(String[] args) 
10     {
11         
12         double numOfValues = 0;  //counter
13         double sumOfValues = 0;  //accumulator
14         double value, average;
15 
16         // the Scanner class will be used for accepting input from the Console.
17         Scanner sc = new Scanner(System.in);
18 
19         System.out.println("This program will add up the numbers you enter");
20         System.out.println("until you enter a 0, at which point it will show");
21         System.out.println("you the average of all the numbers you entered \n");
22 
23         do{
24             System.out.println("Please enter a value");
25             value = sc.nextDouble();
26 
27             if (value != 0)
28             {
29                 numOfValues ++;
30                 sumOfValues = sumOfValues + value;
31             }
32         } while (value != 0);
33 
34         average = sumOfValues/numOfValues;
35         System.out.println("The average of all numbers entered is: " + average);
36     }
37 }
38 
39