0
Please explain this even number generator ?
public class Program { public static void main(String[] args) { for(int x=0; x<=10; x++) System.out.println(x++); } }
4 odpowiedzi
+ 3
First 0 is printed and then it gets incremented by due to x++ in print statement and then it gets incremented by 1 again inside for loop ,so now x is 2 and it is printed and so on
+ 1
Every loop prints in a newline
+ 1
Mons Joseph because '0' is also considered as an even number.
Now, increment operator is used to increment value by 1 and it is of two types - post increment operator and pre increment operator.
Over here , we are using post increment operator in which the value is first used and then incremented. Like over here, in this code first the value is printed and then incremented by one.
Hope it helps...
0
# Abay if so, why is the first output 0 and not 2?