数组有什么特性?
数组可以是任何数据类型,数组中元素的数据类型必须相同,数组中的元素是有序的,即是索引的顺序。
数组的长度是定长的,创建了便不可以更改,数组的下标范围是0到length-1。
数组是引用数据类型,数组同时也是一个对象。
判断一个字符数组中是否有指定的子字符串,有则打印Yes,没有打印No。
1 2 3 4 5 6
| public static void findSonstr(String[] arr,String word) { for (int i=0;i<arr.length,i++) if (word.equals(arr[i])) System.out.println("yes"); System.out.println("no"); }
|
使用冒泡排序完成对数组的排序。
1 2 3 4 5 6 7 8 9 10
| public static void arrList(int a[]) { int temp; for (int i=0;i<a.length;i++) for(int j=i+1;j<a.length;j++) if (a[i] < a[j]) { temp=a[j]; a[j]=a[i]; a[i]=temp; } }
|