数组的使用
package array; import java.util.Arrays; public class demo04 { public static void main(String[] args) { int[] a = {1,2,3,456,74,89,25}; // toString打印或遍历数组元素 System.out.println(Arrays.toString(a)); printarrays(a); Arrays.sort(a);//Arrays方法对数组进行排序 System.out.println();//换行 System.out.println(Arrays.toString(a));
Arrays.fill(a,0)//把数组a全部赋值为0 } public static void printarrays(int[] a1){ for (int i = 0; i < a1.length; i++) { if(i==0) { System.out.print("["); } if(i==a1.length-1) { System.out.print(a1[i]+"]");//最后一个数据时输出数据和"]" } else System.out.print(a1[i]+", "); } } }