两数组相加java_Java将两个整数数组元素中的值相加

更新时间:2023-05-04 02:05:22 阅读: 评论:0

两数组相加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)

本文发布于:2023-05-04 02:05:22,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/522138.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:数组   元素   相加
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图