# 用简单的术语定义和使用Java数组

1.检查数组的有序性

public static boolean isUp(int[] array){ for (int i = 0; i lt;array.length-1 ; i++) { if(array[i]gt;array[i+1]){ return false; } } return true; } public static void main(String[] args) { int[] array = {12,13,14,15,16,17,18}; System.out.println(isUp(array)); }}

2.数组排序(冒泡排序)public class TestDemo { public static void bubbleSort(int[] array){ for (int i = 0; i lt;array.length-1 ; i++) { boolean flg = false; for (int j = 0; j lt;array.length-1-i ; j++) { if(array[j]gt;array[j+1]){ int tmp = array[j]; array[j] = array[j+1]; array[j+1]= tmp; flg = true; } } if(flg = false){ return; } } } public static void main(String[] args) { int[] array = {12,1,23,15,16,13,17}; bubbleSort(array); System.out.println(Arrays.toString(array)); }}

Java数组排序函数:

3. 给定一个整型数组

public static void func(int[] array){ int i = 0; int j = array.length - 1; while(i lt;j){ while(i lt; j amp;amp; array[i] % 2 == 0){ i++; } while (i lt; j amp;amp; array[j] % 2 != 0){ j--; } int tmp = array[i]; array[i] = array[j]; array[j] = tmp; } } public static void main(String[] args) { int[] array = {1,4,3,6,8,5,9}; func(array); System.out.println(Arrays.toString(array)); }

4.数组的拷贝

Java中所有的源代码都是左闭右开的。

5. 定义二维数组

6.打印二维数组

Java二维数组的专门化