Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

fill an array with random numbers between 1 and 100 java

import java.util.Scanner;
import java.util.Arrays;


public class RndArray{
	public static void main(String[] args){
    
		Scanner scan = new Scanner(System.in);
        int arrLength;
        
		System.out.println("Enter your array's length");
		arrLength = scan.nextInt();
		int [] arr = new int [arrLength]; // between [] array's length

		for(int i = 0 ; i<arrLength ; i++){
        	arr[i] = (int) (Math.random()*100 + 1);
            }
         System.out.println(Arrays.toString(arr));
         }
}	
 
PREVIOUS NEXT
Tagged: #fill #array #random #numbers #java
ADD COMMENT
Topic
Name
4+3 =