代码如下:
1.package com.chen.base.Array; public class ArrayDemo05 { public static void main(String[] args) { //[4][2] int[][] array = {{1,2},{2,3},{3,4},{4,5}}; for (int i = 0; i < array.length; i++) { for (int j = 0; j < array[i].length; j++) { System.out.println(array[i][j]); } } } //打印数字元素 public static void printArray(int[] arrays){ for (int i = 0; i < arrays.length; i++) { System.out.print(arrays[i]+" "); } } } -------------------------------------------------------------------------------- 2.package com.chen.base.Array; import java.util.Arrays; public class ArrayDemo06 { public static void main(String[] args) { int[] a = {1,2,3,4,9090,31231,543,21,3,23}; System.out.println(a); //[I@5fd0d5ae //打印数组元素 Arrays.toString //System.out.println(Arrays.toString(a)); Arrays.sort(a); //数组进行排序 System.out.println(Arrays.toString(a)); Arrays.fill(a,2,4,0); System.out.println(Arrays.toString(a)); } public static void printArray(int[] a){ for (int i = 0; i < a.length; i++) { if (i==0){ System.out.print("["); } if (i==a.length-1){ System.out.print(a[i]+"]"); }else { System.out.print(a[i] + ", "); } } } }
点击跳转视频
加油!追梦人。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)