The loop becomes an infinite loop. Those two characters make a big difference!
Here is a fragment of the program, with those two braces removed:
if ( N >= 0 ) { while ( N > 1 ) fact = fact * N; N = N - 1; System.out.println( "factorial is " + fact ); } else { System.out.println("N must be zero or greater"); }
This fragment looks OK, but remember that blank lines and indenting are for people, not for the compiler. What the compiler sees is:
if ( N >= 0 ) { while ( N > 1 ) fact = fact * N; N = N - 1; System.out.println( "factorial is " + fact ); } else { System.out.println("N must be zero or greater"); }
Now, it is clear that N does not change.
The condition N > 1
is always
true, and the loop continues forever.
What would happen
if the brace after the else
and its matching
brace were removed?