# One fast question

• November 23rd, 2013, 08:54 AM
One fast question
Would you please tell me why my output is always 0.0 ? i want my program to print the sum of the values that are less than the average of all of the values generated .
Code java:

```import java.util.*;   public class Test { public static void main(String[] args) { double[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; double result = sumLessThanAverage(numbers); System.out.println(result); }   public static double sumLessThanAverage(double[] a) { int sum = 0; int less = 0; for (int i = 0; i < a.length-1; i++) {   sum += a[i]; double crazy = sum / a.length; if (i < crazy) less += i;   }   return (double) less;   } }```
• November 23rd, 2013, 09:01 AM
GregBrannon
Re: One fast question
Please give your threads better titles. Fast questions are never fast, easy never easy, etc. If they were, why would you need to ask them?

Class names begin with capital letters in Java. It's important.

Fast answer: The reason your output is always zero is because of integer math.

If you want a longer answer, let us know (but don't start a new thread called "One Long Answer.")
• November 23rd, 2013, 09:04 AM
Re: One fast question
Yes I do like a longer answer , and sorry for posting my thread titled " Easy " will be making sure next time to write my title better.
• November 23rd, 2013, 09:20 AM
GregBrannon
Re: One fast question
An integer divided by an integer will result in an integer not a decimal. What's 5 / 3 when 5 and 3 are both integers? Try it and see. What's 3 / 5? You've already tried that. What was the answer? To achieve a double result, one of the numbers must be something other than an integer. Try the same calculations above using 5.0 / 3, 5 / 3.0, and 3.0 / 5.
• November 23rd, 2013, 09:29 AM
Re: One fast question
Yes i am aware of these facts that integer divided by an integer will result an integer but if a double divided by an integer will result a double , however i treid setting all of my int to double and insted of
{1,2,3,4,5,6,7,8,9}
it is now
{ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 }
But i am still struggling with the same problem.
Please be patient with me Greg i am sorry for not solving the problem but as i said i'm still a beginner thank you.
• November 23rd, 2013, 09:34 AM
GregBrannon
Re: One fast question
Focus on this:

double crazy = sum / a.length;

In fact, describe what the method sumLessThanAverage() is supposed to do. The method returns 'less'. When will less be anything other than 0?