So, my code compiles fine and everything with a do-while loop, but when it counts how many numbers there are and averages them all, the count adds the 0 and the average also includes the 0 which I don't want it to. Please help and thank you in advance!
import java.util.Scanner; //Counts pos #, neg #, and averages them. public class Avg_Pos_Neg_Num { public static void main(String[] args) { //what integers? int numbers = 0; int total = 0; int positive = 0; int negative = 0; int sum = 0; double avg = 0.0; Scanner input = new Scanner(System.in); //Tell user to enter pos and neg numbers with spaces. //while loop do { System.out.print("Enter any positive or negative number (0 ends program): "); numbers = input.nextInt(); total++; if (numbers > 0) {positive++;} else if (numbers < 0) {negative++;} } while (numbers != 0); //Compute sum = (positive + negative); avg = ((double)sum / total); //Output System.out.println("The number of positive numbers is " + positive); System.out.println("The number of negative numbers is " + negative); System.out.println("There are " + total + " numbers"); System.out.println("The average of the numbers is " + avg); } }