public class Demo { public static void main(String[] args) { byte[] a = new byte[2147483647]; a[2147483646] = 100; System.out.println(a[2147483646]); } }
public class Demo2 { public static void main(String[] args) { int[] a = { 1, 3, 5, 7, 9, 0, 1, 3, 1, 5, 0 }; // 统计0的个数 int count = 0; for (int i = 0; i < a.length; i++) { if (a[i] == 0) { count++; } } // 定义一个新数组,长度是a.length-count int[] b = new int[a.length - count]; int j = 0; for (int i = 0; i < a.length; i++) { if (a[i] != 0) { b[j++] = a[i]; } } // 1 3 5 7 9 1 3 1 5 9 for (int i = 0; i < b.length; i++) { System.out.print(b[i] + " "); } // 去掉重复的数字 int[] c = new int[b.length]; int m = 0; // 将b数组中的数据取出,判断在c数组中有没有,如果没有,就放到c数组中,否则不放 for (int i = 0; i < b.length; i++) { // 判断在c数组中是否出现b[i] int t = 0; for (int k = 0; k < c.length; k++) { if (c[k] == b[i]) { t++; } } // 如果t为0,说明在c数组中没有找到相等的数据,就将b[i]放入c数组 if (t == 0) { c[m++] = b[i]; } } // 输出c数组 System.out.println(); for (int i = 0; i < c.length; i++) { System.out.print(c[i] + " "); } // 定义新数组是不包含0的长度 int[] d = new int[m]; for (int i = 0; i < d.length; i++) { d[i] = c[i]; } // 输出d数组 System.out.println(); for (int i = 0; i < d.length; i++) { System.out.print(d[i] + " "); } } }
道友请留步 2025-03-26
道友请留步 2025-03-26
藏家708 2025-03-26
leoaim 2025-03-25
恭明惠 2025-03-26
藏家468 2025-03-26
藏家101 2025-03-25
藏家101 2025-03-25
藏家101 2025-03-25
藏家068 2025-03-25