title: How to add 'n' amount of odd integers?
body: <p>I'm trying to write a program that computes the sum of the first n positive odd integers.</p>
  
  <p>I'm having trouble figuring out how to incorporate n into finding the sum. I already have a do/while loop to ensure I get a positive value when assigning n value. I know that I have to use a for loop but I'm not really sure how I would do that.</p>
  
  <pre><code>Scanner input = new Scanner(System.in); // open input stream
      String cleanUpStr;                      // clean kbd buffer
      int n;                                  // number
      int sum;                                // sum of numbers
      int cntr;                               // counter for loop
  
      cleanUpStr = "nothing yet";
      n = 0;
      sum = 0;
      cntr = 0;
  
      //prompt user for the value of n
      // use a loop to ensure a positive output
      do
      {
          System.out.println("Enter the value of n");
  
          n = input.nextInt();
          cleanUpStr = input.nextLine();
  
          // print error if n is invalid
          if (n &lt; 0)
          {
              System.out.println("Invalid n value of " + n + ", try again.");
          } // end if
  
      }while(n &lt; 0);
  
      for(cntr = 0; cntr &lt; n; ++cntr)
      {
  
  
      } // end for
  
  
  
  
  } // end main
  </code></pre>
  
  <p>For example: if n = 5, then this should compute 1 + 3 + 5 + 7 + 9.</p>