Skip to main content
edited tags
Link
tripleee
  • 191.7k
  • 37
  • 318
  • 367
Post Closed as "Duplicate" by gtgaxiola, Andremoniy, Daniel Pryden, rgettman java
Source Link
HQuser
  • 640
  • 10
  • 29

Questions about Java loops and post/prefix operators

int a=0; for (a=0; a++<=10;) { System.out.print(a+ " "); } Output: 1 2 3 4 5 6 7 8 9 10 11 

Why does it prints 11 when the loop is said to end when the variable “a” reaches 10 also why it doesn’t start with 0 as postfix operator is used?

int a=3, b=4; int c = a + b++; System.out.println(+c); Output: 7 

Why the postfix increment operator doesn’t add a value in variable ‘b’? Shouldn't the output be like ‘8’?