提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
返回数组的函数:向量的加法
public class Main {/* 来 自 N o w J a v a . c o m*/ static int[] VectorAddition(int[] u, int[] v) { int[] result = new int[u.length]; for (int i = 0; i < u.length; i++) result[i] = u[i] + v[i]; return result; } public static void main(String[] args) { int[] x = { 1, 2, 3 }; int[] y = { 4, 5, 6 }; int[] z = VectorAddition(x, y);