Java tutorial
//package com.java2s; //License from project: Open Source License import com.google.common.base.Preconditions; public class Main { public static float length(float[] values) { return (float) Math.sqrt(dot(values, values)); } public static float dot(float[] left, float[] right) { Preconditions.checkState(left.length == right.length); float result = 0; for (int i = 0; i < left.length; i++) { result += left[i] * right[i]; } return result; } }