Java expression compilation error

See English answers > why is n + + + n valid while N + + + n is not? one

int x=-3;
    System.out.println(x-----x);

And this Code:

int x=-3;
    System.out.println(x--- --x);

I think the priority is before, after and after subtraction, then subtraction should be applied

Solution

X – x evaluate from left to right:

((x--)--)-x

The first X - Returns - 3. You cannot apply the – () operator only to variables such as X

That's why you get invalid parameter operation / - error

When you add a space – x – x

It is evaluated as (x –) – (– x)

-3 -   -5    = 2
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>