Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>You ask for input and then throw it away</strong> </p> <pre><code>//in the initialization you do:... float numb = input();//used to store the value of Input() method //and in the loop you do it again, overwrite the first input numb = input(); </code></pre> <p>You should only declare the numb in the preamble and leave the rest to the loop.</p> <p><strong>Problems in the loop</strong> </p> <p>Looking at your loop I see the following problems:</p> <pre><code>while (numb != 0) {//Begin for loop count += 1; //Call Input method input(); &lt;&lt;-- 1. should be removed, input goes nowhere numb = input(); //Method to find the sum of all the numbers inputed sum(add,numb); &lt;&lt;-- 2. should be removed, output goes nowhere add = sum(add,numb); //Used to find the average of all the numbers entered (sum / count) }//End for loop avg(add,count); &lt;&lt;-- 3. why do you keep repeating?? average = avg(add,count);//used to store the average of the numbers </code></pre> <p>Whilst java allows you to call functions (return a value) as if they're procedures (returns nothing aka <code>void</code>), you should only do this if you're not interested in the return value.<br> In this case you're calling the function twice.<br> The first call asks the user for input and then throws the result away, the second call ask the user again and then stores the answer. </p> <p>Because you are running in a loop, it's hard to differentiate the duplication from the loop running twice.<br> You should never have to call a function twice, like you're doing in your loop.</p> <p><strong>You don't have to pre-announce your functions</strong><br> Just state what you want to happen and java will do it. </p> <p><strong>Other issues</strong><br> In this case it's not a problem, because <code>numb</code> is directly inputted by the user. But in general you should never compare a float against an absolute value.<br> The following is not guaranteed to be true. </p> <pre><code>((a/b*b)-a == 0) </code></pre> <p>Because of rounding errors you can get unexpected results, where the outcome is of <code>((a/b*b)-a)</code> is <code>0.00000000001</code> which will cause you test (numb != 0) to fail.<br> Because you're comparing against user input it's fine for now, but if you're checking the output of a calculation, <strong>remember that floating point calculations are inexact!</strong> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload