请设计一个Java程序,程序中要进行数组操作和除法操作,要求对所设计的程序可能出现的异常进行处理。

来源:百度知道 编辑:UC知道 时间:2024/09/28 15:06:08

public class aa {
public static void main(String args[]) {
try {
int n[] = { 1, 3, 4, 5, 6, 7, 8, 9, 0, -1, 6, 34, 44, 33, 54 };
int m = 3;
int[] n1 = zhenchu(n, m);
print(n1);
} catch (Exception e) {
new Exception("数组超长").toString();
}
}

public static int[] zhenchu(int[] n, int m) throws Exception {
int n1[] = new int[3];
int j = 0 ;
for (int i = 0; i < n.length; i++) {
if (n[i] % m == 0) {
n1[j] = n[i];
j++ ;
}
}
return n1;
}

public static void print(int[] n) {
for (int i = 0; i < n.length; i++) {
System.out.print(n[i] + " ");
}
}
}

=你遇到好人,就有人回答了。