title: Sum and average of numbers in Java
body: <p>Here is the code but it's not optimized for all the exceptions. For example, if the user types 0 from the beginning, it will give the division by zero error and also I don't know why the sum of the numbers work.</p>
  
  <p>Basically, I make num = 1 so it's different than 0 so the while loop can start, but in the end, I made sum = sum - 1; but it gave a wrong number.</p>
  
  <p>Please help me.</p>
  
  <pre><code>import java.util.Scanner;
  class Main {
      public static void main (String[] args) {
          int count = 0;
          int num = 1;
          double average = 0.0;
          int soma = 0;
          Scanner scanner = new Scanner(System.in);
          System.out.println("Type a integer. 0 to exit.");
  
          while (num != 0) {
              num = scanner.nextInt();
              sum = sum + num;
              count++;
          }
          if (num == 0) {
              average = sum / (count -1); 
              System.out.println("The sum of the numbers is:  "+ soma);
              System.out.println("The average of the numbers is: "+ media);
          }
      }
  }
  </code></pre>