Exchange positions of the two elements of the list:
int temp = arr [1]; // temp-- to third
ARR [. 1] = ARR [2];
ARR [2] = TEMP;
------------------ ---------------
ARR [. 1] = ARR [2];
ARR [2] = TEMP;
------------------ ---------------
Two heavy cycle:
number of control lines layer, inner layer to control the number of columns.
99 cycles for double printing multiplication table:
Package. 3;
public class ___ {print multiplication table the 2_1-th
public static void main (String [] args) {
for (int I =. 1; I <=. 9; I ++) {
for (int. 1 = J; J <= I; J ++) {
of System.out.print (J + "*" + I + "=" + I * + J "\ T");
}
System.out.println ();
}
/ / * 1 = 1 1
// 2 1 = 2 * 2 * 2 = 4
// 3 = 1 * 2 * 3 * 3 = 63 3 = 9
@ 1 = 4 * 4 * 2 * 4 = 8 4 3 12 is. 4. 4 = * = 16 // Print (columns + "*" + the number of lines () + "=" ranks multiplication); } } ----------------- -----------------
number of control lines layer, inner layer to control the number of columns.
99 cycles for double printing multiplication table:
Package. 3;
public class ___ {print multiplication table the 2_1-th
public static void main (String [] args) {
for (int I =. 1; I <=. 9; I ++) {
for (int. 1 = J; J <= I; J ++) {
of System.out.print (J + "*" + I + "=" + I * + J "\ T");
}
System.out.println ();
}
/ / * 1 = 1 1
// 2 1 = 2 * 2 * 2 = 4
// 3 = 1 * 2 * 3 * 3 = 63 3 = 9
@ 1 = 4 * 4 * 2 * 4 = 8 4 3 12 is. 4. 4 = * = 16 // Print (columns + "*" + the number of lines () + "=" ranks multiplication); } } ----------------- -----------------
Copy List:
sequentially removed old elements in the list, to the new list are installed;
int [] oldArray =
{11,22,44,263,55,6,4,7}; int [] newArray = new int [oldArray.length ]; for (int I = 0; I <oldArray.length; I ++) { // sequentially removed old elements in the list, to the new list are installed newArray [I] = oldArray [I]; ------- ---------------------------
sequentially removed old elements in the list, to the new list are installed;
int [] oldArray =
{11,22,44,263,55,6,4,7}; int [] newArray = new int [oldArray.length ]; for (int I = 0; I <oldArray.length; I ++) { // sequentially removed old elements in the list, to the new list are installed newArray [I] = oldArray [I]; ------- ---------------------------
Sorting an array:
// arr operation. Sort.
Arrays.sort (arr); (Method)
---------------------------------
// arr operation. Sort.
Arrays.sort (arr); (Method)
---------------------------------
int max = a > b ? a : b;
---------------------------------
Two-dimensional array:
// three forms
int [] [] intArray;
float floatArray [] [];
Double [] doubleArray []
--------------------- ------------
// three forms
int [] [] intArray;
float floatArray [] [];
Double [] doubleArray []
--------------------- ------------
Method, function - Syntax:
access modifier return type function name (parameter list) {
function body}
public static void getArrayMax () {}
void empty;
access modifier return type function name (parameter list) {
function body}
public static void getArrayMax () {}
void empty;
---------------------------------
迭代、遍历:
// 1:先取出小容器,
//2:然后再取小容器里面的元素
// 1:先取出小容器,
//2:然后再取小容器里面的元素
for (int i = 0; i < arr.length; i++) {
// arr[i] 代表小容器。
for(int j = 0;j<arr[i].length;j++) {
System.out.print(arr[i][j]);
}
System.out.println();
}
// arr[i] 代表小容器。
for(int j = 0;j<arr[i].length;j++) {
System.out.print(arr[i][j]);
}
System.out.println();
}
---------------------------------
查找某个列表中是否存在某个元素:
/**
* 查找某个列表中是否存在某个元素。
* 存在就提示存在,
* 不存在就提示不存在。
* 带参。无返回值。
* 1:参数列表。int []arr,int num
* 2:返回值类型。void
*/
public static void findNum(int [] arr,int num) {
for(int i =0;i<arr.length;i++) {
if(arr[i] == num) {
System.out.println("找到了");
break;
}
}
查找某个列表中是否存在某个元素:
/**
* 查找某个列表中是否存在某个元素。
* 存在就提示存在,
* 不存在就提示不存在。
* 带参。无返回值。
* 1:参数列表。int []arr,int num
* 2:返回值类型。void
*/
public static void findNum(int [] arr,int num) {
for(int i =0;i<arr.length;i++) {
if(arr[i] == num) {
System.out.println("找到了");
break;
}
}
---------------------------------