title: Sum the odd numbers in a loop
body: <pre><code>public static void main(String[] args) {
  
      int maxNum, sum, counter; // input value
      Scanner input = new Scanner(System.in); 
  
      System.out.print("How many odd numbers should I add up?: ");
      maxNum = input.nextInt();   
  
      sum = 0;
  
      for (counter = 1; counter &lt; maxNum; counter++)
      {            
         sum = counter + maxNum;                        
      }
  
      System.out.println("\n" + "The sum of the odd numbers between 1 and " + maxNum + " is: " + sum);                 
  }
  </code></pre>
  
  <p>And according to that specific code, it's supposed to solve addition problems through odd numbers only. </p>
  
  <p>Now I tried it for one number, 5, and according to my output: </p>
  
  <pre><code>How many odd numbers should I add up?: 5
  
  The sum of the odd numbers between 1 and 5 is: 9
  </code></pre>
  
  <p>It works. But when I tried it out for another number, 10, something went wrong:</p>
  
  <pre><code>How many odd numbers should I add up?: 10
  
  The sum of the odd numbers between 1 and 10 is: 19
  </code></pre>
  
  <p>I know my math problems, but odd numbers from 1 to 10 don't add up to 19, it adds up to 25.</p>
  
  <p>Something is wrong with the code. Can anyone figure out what went wrong?</p>