Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a number of problems with your code. I'd rather you work through the problem yourself. You can use "println" debugging to print out the variables along the way if you don't know how to debug code.</p> <p>Take the input 3 and 1 and walk through your program line by line and think about what the answer is going to be in your head (or on paper). See if that matches your expected results.</p> <p>Here are some general comments about your code:</p> <ul> <li>Consider breaking the different output into different subroutines: <code>dumpOddNumbers(low, high), sumEvenNumbers(low, high), ...</code></li> <li>Try to limit a variables scope as much as possible. Don't define the variables at the top and then use them later. Try to define them right before you need them. This will limit your unintended consequences. Try to not re-use variables unless it is temporary counters.</li> <li>while (tempnum &lt;= secondnum) These sort of lines should be <code>for</code> loops. One of the problems with the code is that if the first number is &lt; then the second (the input 1 10 for example), the program loops forever because tempnum is not incremented if the number is odd.</li> <li><code>while (tempnum &lt;= secondnum)</code> should probably be <code>for (int tempnum = firstnum; tempnum &lt;= secondnum; tempnum++)</code></li> <li><code>while (number &lt;= 10)</code> should be <code>for (int number = 1; number &lt;= 10; number++)</code></li> <li>You define the message at the top of your program but you shouldn't tack on results later. Do something like <code>println(msgString + resultValue)</code>.</li> <li>Take a look at <code>StringBuilder()</code> instead of <code>msg = msg + ...</code> type of logic. Much more efficient.</li> <li>When you check the numbers are in the right order and spit out an error message, are you sure you want to continue? I think you should <code>return</code> there.</li> <li><p>The following code does not match the comment. Which is correct?</p> <pre><code>// while the frist number is greater, do this while (tempnum &lt;= secondnum) { </code></pre></li> </ul> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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