AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-programming: Explain the result of the following java code?


int i,j,k;
for(i=1;i<=4;++i) {
for(k=1,j=i;k<=i;k++,j+=2)
System.out.print(" "+j);
System.out.println();
}

corejava x 351
programming x 167
Posted On : 2016-08-06 09:09:02.0
profile MOHAMMAD SALEEM BASHA - anyforum.in MOHAMMAD SALEEM BASHA
266150
up-rate
-3
down-rate

Answers


Output of above program will be:

1
2 4
3 5 7
4 6 8 10

in for loop condition k=1;k<=i is limiting the numbers as 1 in 1st row print only numbers, 2nd row print only 2 numbers, in 3rd row print only 3 numbers. and j=i;j+=2, initiating j which we are printing in each row as we can see in 1st row is start j as 1, 2nd row as 2, 3rd row as 3 and j=j+2 is printing the number with increment of 2.

Posted On : 2016-08-07 00:26:05
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523187021168
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in