提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
计算作为数组给出的两个向量的内积
class Main { static double innerproduct(int[] x, int[] y) { double sum = 0.0;// 来自 时代Java公众号 - N o w J a v a . c o m System.out.println("Dim of vector x:" + x.length + " Dim of vector y:" + y.length); for (int i = 0; i < x.length; ++i) sum = sum + x[i] * y[i]; return sum; } public static void main(String[] args) { int dimension = 30; /* *来 自 nowjava.com - 时 代 Java */ int[] v1, v2; v1 = new int[dimension]; v2 = new int[dimension]; for (int i = 0; i < dimension; i++) { v1[i] = (int) (Math.random() * 100); // random int [0,99] v2[i] = (