两数组相加java_Java将两个整数数组元素中的值相加//wjava;
/*时代Java - N o w J a v a . c o m 提 供*/
public class Main {
p二世胡亥
ublic 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 result;
}
}
/**
* 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)
throws 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 arrays 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 ArithmeticException();
} 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 arra网络个性签名
ys.
* @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 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 two matrices of doubles element-wi.
*
* @param a Matrix of doubles.
* @param b Matrix of doubles.
* @return Element-wi sum of the tw志愿者的英语
o 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 ar中关村笔记本
e * not of the same size.
*/
public static double[][] addElementwi(double[][] a, int[][] b)