Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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;
        }
    }
}