title: Java program infinite loop in sum of even integers
body: <p>I am creating a program that prints the sum of the even numbers from a range of 0 to the number that the user entered. For example, if the user entered the number 20, the program would calculate the sum of all of the even numbers between 0 and 20.</p>
  
  <p>When I tested the program out with the number 10, it worked. But I tried using a different number, 35, and it was just stuck in an infinite loop. I would appreciate any and all help. The code will be posted below:</p>
  
  <p>(Edit) Thanks for the feedback everyone! After talking with a friend, we realized that the solution is actually pretty simple. We were just making it complicated. Still, thanks for all of the suggestions.</p>
  
  <pre><code>//**************************************************************
   // Prints the sum of the even numbers within a range of 0
   // and the integer that the user enters.
   //
   // @me
   // @version_1.0_11.7.17
   //**************************************************************
   import java.util.Scanner;
  
  public class EvenNumbersSum
  {
      public static void main(String[] args)
      {
          Scanner input = new Scanner(System.in);
          int user_num = 2;   // variable that stores the user's number
          int sum;    // stores the sum of the needed values
  
          System.out.print("Enter an integer greater than or equal to, 2: "); // prompt user for input
          user_num = input.nextInt();
  
          // checks to see if the value entered is valid or not.
          while (user_num &lt; 2)
          {
              System.out.println("Invalid entry. Must enter an integer greater than or equal to, 2.\n");
              System.out.print("Enter an integer greater than or equal to, 2: ");
              user_num = input.nextInt();
          }
  
          // starts adding the values
          for (sum = 0; sum &lt;= user_num;)
          {
              if (user_num % 2 == 0)  // checks if the number is even
                  sum+=user_num;  // add the number to sum
              else
                  continue;  // I thought that I might need this, but ended up changing nothing.
          }
  
          System.out.println();   // extra line for cleanliness
          System.out.printf("The sum of the even numbers between 0 and %d is %d.", user_num, sum);    // prints the result
      }
  }
  </code></pre>