# need some help finding average on java

• 09-28-2010, 05:13 PM
jtw0812
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!
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); } }```
• 09-28-2010, 06:16 PM
PhHein
Get rid of that code for now and take a pencil to write down the algorithm in pseudo code.
• 09-29-2010, 04:26 AM
Eranga
@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.