Write a program that always asks the user to enter a number. When the user enters the negative number -1, the program must stop requesting the user to enter a number. The program must then calculate the average of the numbers entered exclusive of the -1. Make use of the while loop repetition structure to implement the program.
This is my solution, but the problem is that I cant exclude the negative number from the sum. Please help
Import javax.swing.*;
public class whileloop
{
    public static void main (String [] args ) 
    {
       int i =0, tot = 0;
       int count = 0;
       double avg = 0.0;
       while(i != -1) 
       {
           i = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter a number");
           if(i != -1)
           {
              tot += i; 
              count++;
              avg = sum/count;
              System.out.println("Sum: " + sum + "\t\t" + "Average: " + avg); 
           }
       }
       System.out.println();
    }
}
 
     
     
     
     
    