Programming..........java


#1

consider the following code segment

for(int i=0;i<20;i=i+2)
{
if(i%3==1)
System.out.print(i+" ");
}
what is printed as a result of executing the above code segment?


#2

4 10 16
Because on each loop, value of i will increase by 2 starting from 0, values will be 0,2,4,6,8,10,12,14,16,18. Now for each values of i, it will check whether the remainder on dividing these no by 3 is 1 or not. Then, it will print the idle numbers following with a space.


#3

4 10 16
as you used ‘+’ symbol to concatinate so each of the output will be on same line with space separated and the explanation of Utsav_Mathur is totally correct and i totally appreciate that