两数组相加java_Java将两个整数数组元素中的值相加//wjava;
/*时代Java - N o w J a v a . c o m 提 供*/
public class Main {
public static void main(String[] argv) throws Exception {
int[] a = new int[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };英语单词缩写
int[] b = new int[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
System.out.println(java.String(addElementwi(a, b)));
}
/**
* Adds up the values in the two arrays of integers element-wi.
*
* @param a Array of integers.
* @param b Array of integers.
* @return Element-wi sum of arrays.
* @throws ArithmeticException Throws an exception when the arrays differ in
* length.
*/
public static int[] addElementwi(int[] a, int[] b)
throws ArithmeticException {/** 时 代 J a v a 公 众 号 - 提供 **/
if (a.length != b.length) {
throw new ArithmeticException();
} el {
int[] result = new int[a.length];
for (int i = 0; i < a.length; i++) {
result[i] = a[i] + b[i];
}
return r野生何首乌
esult;
}
}
/**
* Adds up the values in中国最大的沙漠
the two arrays of doubles element-wi.
*
* @param b Array of doubles.
* @return Element-wi快乐的暑假
sum of arrays.
* @throws ArithmeticException Throws an exception when the arrays differ in * length.
*/
public static double[] addElementwi(double[] a, double[] b)
throw黄渤影帝
s ArithmeticException {
if (a.length != b.length) {
throw new ArithmeticException();
} el {
double[] result = new double[a.length];
for (int i = 0; i < a.length; i++) {
result[i] = a[i] + 澳门最好的大学
b[i];
}
return result;
}
}
/**
* Adds up the values in the two arrays of longs element-wi.
*
* @param a Array of longs.
* @param b Array of longs.
* @return Element-wi sum of arrays.
* @throws ArithmeticException Throws an exception when the arrays differ in * length.
*/
public static long[] addElementwi(long[] a, long[] b)
throws ArithmeticException {
if (a.length != b.length) {
throw new ArithmeticException();
} el {
long[] result = new long[a.length];
for (int i = 0; i < a.length; i++) {
}
return result;
}
}
/**
* Adds up the values in the two arrays of floats element-wi.
*
* @param a Array of floats.
* @param b Array of floats.
* @return Element-wi sum of arrays.
* @throws ArithmeticException Throws an exception when the ar营销案例
rays differ in * length.
*/
public static float[] addElementwi(float[] a, float[] b)
throws ArithmeticException {
if (a.length != b.length) {
throw new ArithmeticException();
} el {
float[] result = new float[a.length];
for (int i = 0; i < a.length; i++) {
result[i] = a[i] + b[i];
}
return result;
}
}
/**
* Adds up the values in the two arrays of bytes element-wi.
*
* @param a Array of bytes.
* @param b Array of bytes.
* @return Element-wi sum of arrays.
* @throws ArithmeticException Throws an exception when the arrays differ in * length.
public static byte[] addElementwi(byte[] a, byte[] b)
throws ArithmeticException {
if (a.length != b.length) {
throw new ArithmeticExcep试用期自我评价
tion();
} el {
byte[] result = new byte[a.length];
for (int i = 0; i < a.length; i++) {
result[i] = (byte) (a[i] + b[i]);
}
return result;
}
}
/**
* Adds up the values in an array of doubles and an array of integers
* element-wi.
*
* @param a Array of doubles.
* @param b Array of integers.
* @return Element-wi sum of arrays.
* @throws ArithmeticException Throws an exception when the arrays differ in * length.
*/
public static double[] addElementwi(double[] a, int[] b)
throws ArithmeticException {
if (a.length != b.length) {
throw new ArithmeticExcepti冬天脚出汗
on();
} el {
double[] result = new double[a.length];
for (int i = 0; i < a.length; i++) {
result[i] = a[i] + b[i];
}
return result;
}
/**
* Adds up two matrices of doubles element-wi.
*
* @param a Matrix of doubles.
* @param b Matrix of doubles.
* @return Element-wi sum of the two matrices.
* @throws ArithmeticException Throws an exception when the two matrices are * not of the same size.
*/
public static double[][] addElementwi(double[][] a, double[][] b)
throws落莫
ArithmeticException {
if (a.length != b.length || a[0].length != b[0].length) {
throw new ArithmeticException();
} el {
double[][] result = new double[a.length][a[0].length];
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[0].length; j++) {
result[i][j] = a[i][j] + b[i][j];
}
}
return result;
}
}
/**
* Adds up two matrices of doubles and integers element-wi.
*
* @param a Matrix of doubles.
* @param b Matrix of integers.
* @return Element-wi sum of the two matrices.
* @throws ArithmeticException Throws an exception when the two matrices are * not of the same size.
*/
public static double[][] addElementwi(double[][] a, int[][] b)