Translate to english

Discussion in 'Java' started by Tavish Muldoon, Aug 23, 2004.

1. Tavish MuldoonGuest

Hello,

Would someone be able to explain what the resultant would be of this statement:

int i = 2;
int j = 3;
int k = 4;

i += j += ++k;

Would some one be able to translate this into 'english'?

I see it as 'add 1 to k' which now equals 5
then 'add 5 to j' which is 3+5=8
then 'add 2' which is the value of i
for a grand total of 10.

Is this correct?

Thanks,

Tmuld.

Tavish Muldoon, Aug 23, 2004

2. Elie De BrauwerGuest

On Mon, 23 Aug 2004 07:18:44 -0700, Tavish Muldoon wrote:

> Hello,
>
> Would someone be able to explain what the resultant would be of this statement:
>
> int i = 2;
> int j = 3;
> int k = 4;
>
> i += j += ++k;
>
>
> Would some one be able to translate this into 'english'?
>
> I see it as 'add 1 to k' which now equals 5
> then 'add 5 to j' which is 3+5=8
> then 'add 2' which is the value of i
> for a grand total of 10.
>
> Is this correct?
>

k=k+1;
// k = 5
j= j + k;
// j = 8
i= i + k;
// i = 10;

You assumption was correct, but the easiest way to be sure is by coding it.

my 2 cents

--
Elie De Brauwer
http://www.de-brauwer.be

No animals were hurt and no microsoft products were used during the
creation of this e-mail

Elie De Brauwer, Aug 23, 2004