Java: sum of two integers being printed as concatenation of the two

前端 未结 10 2027
忘了有多久
忘了有多久 2020-12-03 19:41

Consider this code:

int x = 17;
int y = 013;
System.out.println(\"x+y = \" + x + y);

When I run this code I get the output 1711. Can anybod

10条回答
  •  萌比男神i
    2020-12-03 19:48

    It appears to be interpreting y as using octal notation (which evaluates to 11). Also, you're concatenating the string representations of x and y in System.out.printLn.

提交回复
热议问题