programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# Operators

Ranch Hand
Posts: 36
• Number of slices to send:
Optional 'thank-you' note:
public class Q7
{
public static void main(String[] args)
{

int i=3;
System.out.println(ii*=2 + i++);
}
}

I came across this question.When I ran this o/p is 15.How can o/p is 15.

Ranch Hand
Posts: 657
• Number of slices to send:
Optional 'thank-you' note:
I'm assuming the 'ii' is a typo (else it won't compile), and that the line actually reads as follows:

If so, the logic is as follows:

i = 3 * (2 + 3); // i++ evaluates to the original value of i
i = 3 * 5;
i = 15;

Does that help? I can probably guess the next question, though. It's, "where did my incremented value go?", right? Good question!

It helps to understand the difference between variables and an operand stack. I'll write up the steps from a bytecode point of view...

Hope this helps...
[ October 31, 2005: Message edited by: Steve Morrow ]

Alpana Singh
Ranch Hand
Posts: 36
• Number of slices to send:
Optional 'thank-you' note:
Now I got it.I was confused ny i++.

Thanks for detailed explanation.

 Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters?