赞
踩
int[] x = new int[3]{1,2,3};
正确写法:
- int[] x = new int[3];
- x[0] = 1;
- x[1] = 2;
- x[3] = 3;
或者:
int[] x = new int[]{1,2,3};
- package jjm;
-
- import java.util.Arrays;
-
- public class Main {
-
- public static void main(String[] args) {
- int[] a = new int[] {3,4,5,6};
- int[] a2 = new int[]{3,4,5,6};
- System.out.println("a数组与a2数组是否相等:"+Arrays.equals(a, a2));
- int[] b = Arrays.copyOf(a, 6);
- System.out.println("a数组和b数组是否相等:"+Arrays.equals(a,b));
- System.out.println("b数组的元素为:"+Arrays.toString(b));
- Arrays.fill(b, 2, 4, 1);
- System.out.println("b数组的元素为:"+Arrays.toString(b));
- Arrays.sort(b);
- System.out.println("b元素的元素为:"+Arrays.toString(b));
- }
-
- }
-
结果如下: - a数组与a2数组是否相等:true
- a数组和b数组是否相等:false
- b数组的元素为:[3, 4, 5, 6, 0, 0]
- b数组的元素为:[3, 4, 1, 1, 0, 0]
- b元素的元素为:[0, 0, 1, 1, 3, 4]
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。