Help with while iterative procedure

Hey there,

I could use some help with my homework once again.

Here's the question:

Write a Java program which uses a while iterative procedure to allow the user to enter a list of numbers terminated by 0, and which totals them, finds their average and displays their total and average.

I'm not completely sure how to write the code to produce both sum and average, but I googled and researched and gave it a shot and... well, my code definitely is not right. If anyone can explain how to write this and maybe let me know where I'm going wrong, I'd really appreciate it.

import java.util.Scanner;

public class SwitchStatement {

public static void main(String[] args) {

Scanner inp = new Scanner (System.in);

int x = 1;

int sum = 0;

System.out.println ("Please enter a sequence of integer numbers ending with 0");

while (x != 0) {

x = inp.nextInt();

sum +=x;

}

System.out.println ( "Sum of integers is " + sum);

int count; // The number of positive integers.

count = 0;

System.out.println(x);

while (x != 0) {

count++; // Count the input by adding 1 to count.

x = ((int)sum) / count;

System.out.println ( "Average of integers is " +x);

}

}

}

When I run the prorgram, I can enter the integers, and get the sum, but I can't get the average to display.

Here's what it looks like:

Please enter a sequence of integer numbers ending with 0

21

46

0

Sum of integers is 67

0

Any help/explanation would be really appreciated. Thank you!