I just tested the following code:
int x = 90; x = x - (x = x - 1); System.out.print(x);
He is typing 1.
As far as I understand, everything goes in the following order:
x - 1
x
x - the new value of x
I do not understand why x, from which we subtract the result of paragraph 2, it still has an initial value after paragraph 2. What am I missing?
From https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html
, , ; .
90 - (90 - 1) = > 1
90 - (90 - 1)
1
. , .
@ruakh, JLS - .
http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.7.
, .(ยง15.26.2), , , ., , -, .
, .
(ยง15.26.2), , , .
, , -, .
, , , , , , .
:
int x = 90; x = x - (x = x - 1);
= , .
x = x - (x = x - 1) x - b, b (x = x - 1)
, 90 - b
b, (x = x - 1). , (x = 90 - 1) (x = 89)
, 90 - (x = 89), 90 - 89, 1. , x 1. , (x = 89 ) .
int x = 90; x = x - (x = x - 1); System.out.print(x);` Here x = 90 Goes in two section in your code. First x=90 - , Second (x=90-1); Then x=90 - , x = 89 Then x= 90 - 89 System.out.Print(x); that is x=1;
Source: https://habr.com/ru/post/1659950/More articles:Change NCWidgetDisplayMode programmatically in iOS 10 widgets - iosHow to use TokensRegex rule annotator using Stanford CoreNLP Server? - stanford-nlpSaving and restoring learner LSTM in tensor flow - tensorflowconverting json data to angularjs module into array and graph using c3 chart - jsonc3.js how to set json data in x / y Axis - jsonHow to reset or update KCF tracking ROI when it loses target - c ++Exclude current entry from recent requests in Jekyll? - markupHow to run a unit test Asp.net Core WebAPI project (net452)? - unit-testingNuGet solution with multiple projects - c #clear ROI history of kcf tracking in opencv - opencvAll Articles