-1
public class Class1 {

    public static void main(String[] args) {
        int myFirstNumber =20;
        int mySecondNumber=10;
        System.out.println(myFirstNumber+++mySecondNumber);
    }
}

mySecondNumber should have been incremented to 11, thus making the sum 31

Komal12
  • 3,340
  • 4
  • 16
  • 25
  • 2
    Why do you think "myFirstNumber+++mySecondNumber" means "myFirstNumber+(++mySecondNumber)" and not "(myFirstNumber++)+mySecondNumber"? What's your proof? The output already disproves you. – Tom Jan 16 '18 at 10:29

1 Answers1

9

It's the Java parser interpreting

+++

as (myFirstNumber++)+, rather than +(++mySecondNumber)

We use the term greedy to describe that behaviour; i.e. the parser consumes as much of the input as it can in order to form a meaningful expression.

Be assured, that after the println, myFirstNumber will be 21.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483