Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int[] randomArray = randomArray(5);
        System.out.println(Arrays.toString(randomArray));
    }

    //generate random integer within a range
    public static int randomInt(int low, int high) {
        return (int) (Math.random() * (high - low)) + low;
    }

    public static int[] randomArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = randomInt(0, 100);
        }
        return a;
    }
}