2013年9月4日星期三

The following four questions why this is the result ? Requirementsanalysis

The first question
int x = 1, y = 1;
/ / + + postfix first value in the self- prefix style first from Canada in the comparison
if (x + + == 2 & + + y == 2) {/ / & it treats the whole person to the formula calculation results in x ; = 7 ;
}
System.out.println ("x =" + x + ", y =" + y); x = 2 y = 2 -------- ------------------------------------------- The second question
int x = 1, y = 1;
/ / && if the first expression is determined by results of the entire formula , formula will not be back in operation . if (x + + == 2 && + + y == 2) {
x = 7;}
System.out.println ("x =" + x + ", y =" + y); x = 2 y = 1 -------- -------------------------------------------
third title
int x = 1, y = 1;
if (x + + == 1 | + + y == 1) {
x = 7;
}
System.out.println ("x =" + x + ", y =" + y); x = 7 y = 2 -------- -------------------------------------------
Fourth Question int x = 1, y = 1;
if (x + + == 1 | | + + y == 1) {
x = 7;
}
System.out.println ("x =" + x + ", y =" + y); x = 7 y = 1
------ Solution --------------------------------------------
dares so write in the project which , immediately let him roll ~
------ Solution ----------------------------- ---------------
x + + run after x +1, the value returned is x
+ + x before running the x +1, the value returned is x +1
------ Solution ----------------- ---------------------------
&&, | |
these operators , if interpreted in the inside, if the first expression established , do not operate the second expression , for example, the second question :
if (x + + == 2 && + + y == 2), here is the relationship with the first interpretation of an x + + = 2 does not hold, and the relationship does not hold as long as a whole if expression is not established , all will not execute the second expression , that is, + + y = 2 a .

The fourth question , if (x + + == 1 | | + + y == 1) Here is the relationship or the first interpretation of an x + + = 1 set up , or a relationship, as long as there is a established if expression on the establishment of a true , all do not have to perform a second interpretation of the expression , which is a + + y = 1

&, |
interpretation of these two operators when , whether the first expression can not determine the final result will execute the second expression , such as the first question ,
if (x + + == 2 & + + y == 2), the first x + + = 2, this is not true, but the implementation into play only after x 2, then execute the second expression , + + y = 2, y before adding one becomes two , in the interpretation of this is true , but because the first one is not true, and here is the relationship , if not all of the entire establishment , does not run inside the curly braces x = 7 All end result is x = 2, y = 2

own analysis of the rest of the landlord under the bar , so hard to describe.
------ Solution ---------------------------------------- ----
which do not understand it ? Direct questions pile up . .
------ Solution ---------------------------------------- ----
these are examinations of questions ah , the practical application 'd much
------ Solution ------------------ --------------------------
are interview questions , the project is in the best kind of code at a glance !

没有评论:

发表评论