Please Write and explain about the prior of the given Java code
int i=1;
for (;i<5;i++)
{ }
System.out.println(++i);
Answers
Answered by
1
Answer:
6
Explanation:
The for loop initialization is at the starting.
There are no statements inside the for loop so it won't print but it gets incremented
for 1<5 correct
inc i
2<5 correct
inc i
for 3<5 correct
inc i
for 4<5 correct
inc i here i=5
Now 5<5 condition fails but the i value is 5
++i means to increment (++) first then return the value of i, thus we have ++i
The i value is incremented i = 6
Similar questions
Accountancy,
6 months ago
Biology,
1 year ago
English,
1 year ago
Chemistry,
1 year ago
Chemistry,
1 year ago