Computer Science, asked by Suman1401, 1 year ago

class test
{
public static void main(String[] args)
{
int i;
for(i=1;i<=2;i=i++)
{
System.out.println("Check");
}
}
}


Please anyone explain what's happening here???
Why the value of 'i' does not increments???

Answers

Answered by vaibhavkr4337
0
The output will be:
Check
Check

Explanation : Here, for loop will increase the value of i two times. At first, it is 1 and then it becomes 2 and after that, it becomes 3 but 3 is more than 2 (required condition is i >= 2).
So 'Check' is printed two times on the screen.

I think you are getting the error because you have written 'String[] args' in place of 'String args[]'. The correct format is 'String args[]' and not 'String[] args'.
Similar questions