Java Array initialize arrays with random values

Introduction

The following loop initializes the array array with random values between 0.0 and 100.0, but less than 100.0.

import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    int[] array = new int[5];

    for (int i = 0; i < array.length; i++) { 
      array[i] = (int)(Math.random() * 100); 
    } //  w  w w.ja v  a 2s  . com
    
    System.out.println(Arrays.toString(array));

  }
}



PreviousNext

Related