# Thread: need some help finding average on java

1. Member
Join Date
Sep 2010
Posts
1
Rep Power
0

## need some help finding average on java

I need to write a program that lists nonnegative #s, then display the smallest and largest integer as well as the average. In my program, I have it so it lists the smallest and largest integer but I don't know how to find the averages of the integers, help would be greatly appreciated. thanks!
Java Code:
```public class average
{
public static void main(String[] args)

{
System.out.println("Enter all integers.");
System.out.println("Enter a negative number after");
System.out.println("You have entered all integers");
Scanner keyboard= new Scanner(System.in);
double max=keyboard.nextDouble();
double min=max;
double next=keyboard.nextDouble();

do
{
int numberOfintegers=6;
double average, sum=0;
for (int count =1; count<=numberOfintegers; count++)

{
next=keyboard.nextDouble();
sum=sum+next;
}
if (numberOfintegers>=0)
average=sum/numberOfintegers;

else
System.out.println("No integers to average");
}

while (next>0);
{
if (next>max)
max=next;
else if (next<min)
min=next;
next=keyboard.nextDouble();
}
System.out.println("The highest integer is" + max);
System.out.println("The lowest interger is" + min);
}
}```
Last edited by Eranga; 09-29-2010 at 04:24 AM. Reason: code tags added

2. Get rid of that code for now and take a pencil to write down the algorithm in pseudo code.

3. @OP, please use code tags next time posting. If you don't know how to do it, check on my forum signature. You can find a relevant link.

Regarding your question, just forget about Java. How did you calculate average in maths? If you know the logic what you've to do is, convert it into a Java code.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•