Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Problem with division

import java.util.Scanner;

public class CountPosAndNegNumbers {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int positive = 0;
int negative = 0;
int averagePos = 0;
int averageNeg= 0;

System.out.println("Enter an integer, the input ends if it is 0:");
int numbers = input.nextInt();

do {

if (numbers > 0)
{

positive += numbers;
}

else if (numbers < 0)
{

negative += numbers;
}

numbers = input.nextInt();
averagePos = Math.round(positive);
averageNeg = Math.round(negative);

} while (numbers != 0);

System.out.println("The number of positives is:" + positive);
System.out.println("The number of negatives is:" + negative);
System.out.println("Average of positive numbers:" + averagePos);
System.out.println("Average of negative numbers:" + averageNeg);

}
}

I need help to find the average of the integers that are input but can't manage to solve the problem.

2. ## Re: Problem with division

you can do it easily without calling Math.round()

3. ## Re: Problem with division

If you just want the whole integer (no decimal) then you
need to count the total amount of inputs for each type -
i.e total input of positive, total input of negative. You would
then use these values in the calculation against the totals of
each numeric value result (total of negative numbers etc).