Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

ann chua
Greenhorn
Posts: 2
i have a problem also using the post increment in java. i have this code k=j+++i; where k=0, j=3 and i=10. its answer is 13, how can i make the answer into 14 using the post increment?.

Fidel Edwards
Ranch Hand
Posts: 234
ann chua wrote: how can i make the answer into 14 using the post increment?.

just use k = i+j++;

It would give desired output !

Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
if you want output 14 then space is important here

Fidel Edwards
Ranch Hand
Posts: 234
seetharaman venkatasamy wrote:if you want output 14 then space is important here

seetharaman venkatasamy is right !

fred rosenberger
lowercase baba
Bartender
Posts: 12234
36
Ashish Tiwari wrote:just use k = i+j++;
It would give desired output !

Not according to my tests:

C:\slop>java Test
k is 13
k is 13

C:\slop>

can you do this:

j++;
k = k + i;

or this:

k = j + i;
k++;

Fidel Edwards
Ranch Hand
Posts: 234
fred rosenberger wrote:
Ashish Tiwari wrote:just use k = i+j++;
It would give desired output !

Not according to my tests:

C:\slop>java Test
k is 13
k is 13

C:\slop>

can you do this:

j++;
k = k + i;

or this:

k = j + i;
k++;

Sorry i just forget to comment the line .In fact i was trying something like

It would give the correct output

Maneesh Godbole
Saloon Keeper
Posts: 11257
16
Ann,
Welcome to the Ranch.
Next time, while posting, please use a meaningful subject line

Joanne Neal
Rancher
Posts: 3742
16
Ashish Tiwari wrote:
seetharaman venkatasamy wrote:if you want output 14 then space is important here

seetharaman venkatasamy is right !

Except for the fact that the question asked how to do it using the post increment

ann chua
Greenhorn
Posts: 2
thank you for the help. oh, ok sorry. i will next time.

thank you.