0
public class Sum_of_Numbers {
    public static void main( String [] args)    {

        int sumOfEven = 0;
        int sumOfOdd = 1;
        int even_Times = 0;
        int odd_Times = 0;

        while ((even_Times < 12) || (odd_Times < 13));  {
            sumOfEven = sumOfEven+2;
            even_Times = even_Times+1;
            sumOfOdd = sumOfOdd + 2;
            odd_Times = odd_Times + 1;
            System.out.println("The sum of even integers is " + sumOfEven);
            System.out.println("The sum of odd integers is " + sumOfOdd);
        } 

        System.out.println("The sum of even integers is " + sumOfEven);
        System.out.println("The sum of odd integers is " + sumOfOdd);
    }
}

When I run this code, the loop fails to start and I don't know why.

enter image description here

burntsugar
  • 57,360
  • 21
  • 58
  • 81
  • hmmm. i don't this is a "a simple typographical error" because the semi-colon is legitimate syntax which was used in the wrong context. this is a common mistake, not a common "typo". i doubt the author hit the key by mistake, they thought a semi-colon was required. yes, i admit i used the word typo in my answer. – slipperyseal Jun 22 '17 at 23:37
  • @slipperyseal It's a dupe anyway [...](https://stackoverflow.com/questions/2610679/whats-wrong-with-this-while-loop). – Tom Jun 23 '17 at 09:28

1 Answers1

2

You've used the wrong syntax with the while statement and it's in an infinite loop

    while ((even_Times < 12) || (odd_Times < 13));  {

The semi-colon is closing the statement, so only the conditions within the while loop are executed. even_Times and odd_Times don't increment, so it loops forever.

When the semi-colon is removed, the following { } block will execute within the while loop.

    while ((even_Times < 12) || (odd_Times < 13)) {
slipperyseal
  • 2,728
  • 1
  • 13
  • 15