public class ArrayCopy
{
public static void main(String[] args)
{
int[] a = new int[]{1, 2, 3, 4};
int[] b = new int[]{4};
System.arraycopy(a, 0, b, 0, 4);
for(int i = 0; i < b.length; i++)
{
System.out.print(b[i] + " ");//可编译,无法执行??
}
}
}
2、
public class ThreeDimensionArrayTest
{
public static void main(String[] args)
{
int[][][] a = new int[2][3][4];
System.out.println(a instanceof int[][][]);
System.out.println(a[0] instanceof int[][]);
System.out.println(a[0][0] instanceof int[]);
for(int i = 0; i < a.length; i++)
{
for (int j = 0; j < a[i].length; j++)
{
for(int k = 0; k < a[i][j].length; k++)
{
a[i][j][k] = 100;
}
}
}
}
}
3、冒泡排序
public class BubbleSortTest
{
public static void bubbleSort(int[] array)
{
for(int i = 0; i < array.length - 1; i++)
{
for(int j = 0; j < array.length - i - 1; j++)
{
if(array[j] > array[j + 1])
{
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
System.out.println("第" + (i + 1) + "趟排序");
for(int k = 0; k < array.length; k++)
{
System.out.print(array[k] + " ");//第一趟排序
//4 7 3 2 8
//第二趟排序
//4 3 2 7 8
//第三趟排序
//3 2 4 7 8
//第四趟排序
//2 3 4 7 8
}
System.out.println();
}
}
public static void main(String[] args)
{
int[] array = {4, 7, 8, 3, 2};
bubbleSort(array);
}
}
对比:
public class A
{
public static void bubbleSort(int[] array)
{
for(int i = 0; i < array.length - 1; i++)
{
if(array[i] > array[i + 1])
{
int temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
}
System.out.print(array[i] + " ");//0143
}
}
public static void main(String[] args)
{
int[] array = {1, 0, 4, 8, 3};
bubbleSort(array);
}
}
3、作业:交换排序和快速排序的原理与实现方式