java


What is the order of multiple pre/post incrementations in one line equation in JAVA?


I have this piece of code in JAVA 8:
int x=3;
int y = --x + x++ + --x ;
System.out.print("y: " + y + " x: "+x);
As I understand it should be split like this:
y = 2 + x++ + --x; x = 2
y = 2 + 2 + --x; x = 2
y = 2 + 2 + 1; x = 1
y = 5; x = 2
And it prints y: 6 x: 2
What is the order of operation in here?
It's because of the way pre and post increments work, it gets evaluated like this:
1. y = --x + x++ + --x ;
2. y = 2 + (2)++ + --(3);
3. y = 2 + 2 + 2;
4. y = 6
After 2 decrements and 1 increment, x becomes 2.

Related Links

Maven Installation and Configuration
UploadException on clicking Vaadin7's upload component button
Sending a video file via REST API to JIRA in Java
Beginner: Java While loop won't exit?
How to run jetty server for java junit testing
How to find refraction vector from incoming vector and surface normal
GridBagLayout Grid Width
How to remove line separators from JTextArea in SeaGlass L&F?
Check what all methods were called when I called a method when unit testing
How to reduce cycles spent on /_ah/warmup
Reading in a 2D array from a file through the command line in Java
extending a class whose members are all static
Java code not hitting IF or ELSE in Android Studio [SOLVED]
What is the difference between class.super.method and class.method?
Changing contrast with ImageJ plugin
Magic Square Method needs to output if it is a magic square and the sum of rows and columns

Categories

HOME
winforms
comparison
octobercms
google-docs
infragistics
microservices
ezpublish
opengl-es-2.0
in-app-purchase
medical
cloudkit
maude-system
facebook-php-sdk
offline
google-cloud-spanner
dtrace
iron-router
netflix
clearcase-ucm
tostring
windows-7-x64
connection-string
nhibernate-envers
jquery-ajaxq
orleans
dcevm
zurb-foundation-6
java-7
chromebook
fgetcsv
entitlements
fluentvalidation
libuv
c++-amp
procdump
perlin-noise
webtest
framemaker
android-kernel
mmenu
retina-display
x11-forwarding
libraries
abstract-class
impersonation
jna
hue
ansible-playbook
streamreader
texmaker
ibpy
password-encryption
qcombobox
executenonquery
apple-news
chain-builder
strptime
pango
typescript1.8
windows-iot-core-10
epson
sqldf
webdriverjs
or-tools
url-pattern
spring-android
angular-cache
infix-notation
elements
nsfilemanager
bstr
connect-by
ipconfig
revolution-r
photobucket
uid
spim
jms2
cartesian-product
django-unittest
feedback
fouc
tableau-online
twirl
npapi
sorl-thumbnail
android-imagebutton
qcodo
html-helper
bundles
ember-charts
html5-notifications
geos
bulkloader
dataadapter
android-screen-support
datawindow
tridion-worldserver
removeclass
punbb
winbugs14
.nettiers
sproutcore-2
gin
nhibernate.search
asp.net-profiles
ext3
xetex
spec#
private-members
ajax-forms

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile