0 votes
in JAVA by
Which of the following for loop declaration is not valid?

i) for ( int i = 99; i >= 0; i / 9 )

ii) for ( int i = 7; i <= 77; i += 7 )

iii) for ( int i = 20; i >= 2; - -i )

iv) for ( int i = 2; i <= 20; i = 2* i )

1 Answer

0 votes
by

(i) for ( int i = 99; i>=0; i / 9)

Reason: The first option is not a valid declaration as i/9 is not declared correctly. The correct statement will be:
      for ( int i= 99; i>=0; i= i/9)

Then the code would execute. But without assigning the value of i/9 to a variable, it would not execute, and an exception is thrown, as shown below.

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
      Syntax error on token "/", invalid AssignmentOperator

...