Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (7k points)

Can someone explain to me the output of this Java code

int a=5,i;

i=++a + ++a + a++;

i=a++ + ++a + ++a;

a=++a + ++a + a++;

System.out.println(a);

System.out.println(i);

1 Answer

0 votes
by (13.1k points)

a=5;

i=++a + ++a + a++;

This means  i=6+7+7;

a=5

i=a++ + ++a + ++a;

This means 5+7+8;

The main point is ++a increments the values and immediately returns it.

a++ increments the value but returns the unchanged value. It is executed later.

Want to learn Java? Check out the Java certification from Intellipaat.

Related questions

0 votes
1 answer
asked Nov 26, 2019 in Java by Nigam (4k points)
0 votes
1 answer
0 votes
1 answer
asked Mar 14, 2021 in Java by Jake (7k points)
0 votes
1 answer
0 votes
2 answers

Browse Categories

...