[Solved] Create an array having random numbers (each number being less than 100) with length n


You need to edit your question in order to make it more clear so you’ll get the help you want.
I guess you were trying to get a number from the user, than create an ‘array’ of that number size. Afterwards you want to assign random ‘int’, ranging 0-100 (100 exclusive), for each array index. IN the end output the array values comma separated, 5 in each line.
I wrote a code to do that:

import java.util.Scanner; // import Scanner object to get user input

public class ArrRandomNum {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in); // initialize Scanner object 'input'.
        System.out.print("Enter a number: "); // prompt.
        int n = input.nextInt(); // parse and assign the next int. use lowercase for variables.
        input.close(); // close Scanner object 'input' to avoid resource leaks.

        int[] arr = new int[n]; // initialize array 'arr' of size 'n'.

        for (int i = 0; i < arr.length; i++) {

            arr[i] = (int) (Math.random() * 100); // assign random int 0-100 (100 exclusive)

        }

        for (int j = 0; j < arr.length; j++) {

            System.out.printf("%d, ", arr[j]); // print arr[j] value and a ', '.

            if ((j+1) % 5 == 0) { // every 5 numbers goes down a line.

                System.out.println();

            }
        }
    }
}

1

solved Create an array having random numbers (each number being less than 100) with length n