Study Notes 2, struts2 Study Notes
+ =,-=, * =,/= Implies forced type conversion.
In logical operations, the difference between & and & is:
&: No matter whether the left side is true or false, all operations are performed on the right side.
&: If the left side is false, the right side is not involved in the operation. If the left side is true, the right side is involved in the operation.
An exclusive or operation can exchange two integers (no extra space overhead is required ):
A, B;
A = a ^ B;
B = a ^ B;
A = a ^ B;
There are four common methods to implement two integer exchanges:
1) Introduce 3rd variables temp
2) use an exclusive OR operator ^
3) addition and subtraction
A = a + B;
B = a-B;
A = a-B;
4) Get it by one
B = (a + B)-(a = B );
Use a two-dimensional array to save and output the Yang Hui triangle (different rows have different numbers of data ):
/**
*
*/
Package com. yan. javaTest;
Import java. util. collections;
/**
* @ Author Yan
*
*/
Public class YangHuiSanJiao {
/**
* Yang hui san jiao xing.
*
* 1
* 1 1
* 1 2 1
* 1 3 3 1
* 1 4 6 4 1
* 1 5 10 10 5 1
*
* 1. Mei hang de di yi lie he zui hou yi lie dou shi 1;
* 2. Cong di san hang kai shi zhongjianlie de shuzhi wei shangyihang de qianyilie he dangqianlie
* Shuzhi zhihe.
*
*/
Public YangHuiSanJiao (){
// TODO Auto-generated constructor stub
}
/**
* @ Param args
*/
// Array assignment
Int [] [] yangHuiSanJiaoXing (int [] [] str ){
For (int I = 2; I <str. length; I ++) {// from the third line str [2] [];
For (int j = 1; j <str [I]. length-1; j ++) {// from str [I] [1] ---- str [I] [length-2];
Str [I] [j] = str [I-1] [J-1] + str [I-1] [j];
}
}
Return str;
}
// Array format Initialization
Int [] [] arrInit (int [] [] str, int n ){
For (int I = 0; I <n; I ++ ){
Str [I] = new int [I + 1];
Str [I] [0] = 1;
Str [I] [I] = 1;
}
Return str;
}
Public static void main (String [] args ){
// TODO Auto-generated method stub
System. out. println ("Please input a number to assign the lines of the triangle :");
Pipeline SC = new pipeline (System. in );
Int n = SC. nextInt ();
Int [] [] arr = new int [n] [];
YangHuiSanJiao ys = new YangHuiSanJiao ();
Arr = ys. arrInit (arr, n );
Arr = ys. yangHuiSanJiaoXing (arr );
For (int I = 0; I <arr. length; I ++ ){
For (int j = 0; j <arr [I]. length; j ++ ){
System. out. print (arr [I] [j] + "\ t ");
}
System. out. println ();
}
SC. close ();
}
}