# Basic arithmetic problem.

Tommaso Nuccio

Ranch Hand

Posts: 66

posted 9 years ago

Hi there,

I have a problem to understand this:

the output is 14.

Now my problem here is that LINE 1 can be written as

c = c * a + b

Here now "*" has a higher priority as "+"

and the result must be

c = (2 * 3) + 4

c = 10

Why is it 14?

Or does

c *= a + b;

c = c * a + c * b;

c = c * (a + b);

?

Thanks in advance.

I have a problem to understand this:

the output is 14.

Now my problem here is that LINE 1 can be written as

c = c * a + b

Here now "*" has a higher priority as "+"

and the result must be

c = (2 * 3) + 4

c = 10

Why is it 14?

Or does

c *= a + b;

c = c * a + c * b;

c = c * (a + b);

?

Thanks in advance.

Ciao,<br /> Tommaso<br /> <br />~*~*~*~<br />There are 10 types of people, those who understand binary and those who don't.

Srikanth CS

Greenhorn

Posts: 9

Keith Lynn

Ranch Hand

Posts: 2409

posted 9 years ago

This is from the Java Language Specification 15.26.2.

*A compound assignment expression of the form E1 op = E2 is equivalent to*

E1 = (T )((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once.E1 = (T )((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once.

Tommaso Nuccio

Ranch Hand

Posts: 66

Keith Lynn

Ranch Hand

Posts: 2409