Java arrays and other knowledge
Array copy copy (copy)
Because the size of the array is fixed, so when using array, often have to create a larger or smaller arrays
Then copy the contents of the array that already exist in the new array.
1. Create a new array, one by one through the For loop copies.
2.System a class method ArrayCopy (), is dedicated to a copy of the array elements.
The original formula is as follows:
The first parameter: (copy source array) the src
The second parameter: srcPos (start copying array subscript)
The third parameter: the destination array dest, copy
The fourth parameter: Start index destPos, the destination array
The fifth parameter: int length, the length of the copy
E.g:
int[]score1 = new int[]{89,90,78,88}
int[]score2 = new int[3];
system.arraycopy(score1,0,score2,2,2);
system.out.println(Arrays.tostring(score2));
Bubble Sort:
Comparing the number in front of the back is so large change to the back.
Random Number: - random
Generates a random number, we do not need to write their own algorithms in .Java provides random number generation method Math.random ()
For generating a random number (0,1): the role of
Math.random()
Return Type: double
Return Value: 0 ~ 1 1 fail to
System.out.println(Math.random());
Two-dimensional array:
Is represented by a table in the form of rows and columns, the table data type of each element type is the same data type
Specify a common element with two lower ranks of the table area index is zero-based
All multidimensional arrays are ultimately turned into a one-dimensional array
Just one-dimensional array of elements is an array
Get the length:
int[][]arr=new int[i][j];
arr.length acquired two-dimensional array is the number of rows (i)
arr [i] .length acquired is the number of (j) a two-dimensional array of columns
int[]arr1=new int[3][4];
system.out.println(arr1[0][0]);
Message box shells
JOptionPane.showMessageDialog(null,"欢迎");
输入弹框
JOptionPane.showInputDialog(null,"请输入一个数:");
//
JOptionPane.showMessageDialog(null,"你好");
String str1=JOptionPane.showInputDialog(null,"请输入一个数:");
int a= Integer.parseInt(str1);
String str2=JOptionPane.showInputDialog(null,"请输入一个数:");
int b= Integer.parseInt(str2);
JOptionPane.showMessageDialog(null,str1);
System.out.println(a+b);
换行/n