Java tutorial
//package com.java2s; public class Main { public static void normalize(float[] vector) { double sum = 0.0; for (float x : vector) { sum += x * x; } if (sum == 0) { return; } sum = Math.sqrt(sum); for (int i = 0; i < vector.length; i++) { vector[i] /= sum; } } public static void normalize(double[] vector) { double sum = 0.0; for (double x : vector) { sum += x * x; } if (sum == 0) { return; } sum = Math.sqrt(sum); for (int i = 0; i < vector.length; i++) { vector[i] /= sum; } } }