Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package arraylists; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; import java.util.Random; public class arraylists { public final static int MAX = 1000; static Random rand =

package arraylists;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Scanner;

import java.util.Random;

public class arraylists {

public final static int MAX = 1000;

static Random rand = new Random();

static int rand_int1 = rand.nextInt(1000);

static int rand_int2 = rand.nextInt(1000);

public static void array(int [] a1 ) {

int [] arry = new int[MAX];

for(int i = 0; i < MAX; i++) {

a1[i] = rand_int1;

}

}

public static void arrayList(int [] a2) {

ArrayList num = new ArrayList();

for(int i = 0; i < MAX; i++) {

num.add(i);

}

}

public static void main(String args[]) {

//int [] arry = new int[MAX];

int num;

System.out.println("Enter the number of iterations: ");

Scanner input = new Scanner(System.in);

num = input.nextInt();

I am trying to write functions that generate an array of size MAX and assign them random values using a function for arrays and arraylists. I want to compare the time it takes for it to be added. can you help me with this

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

=+can you write alternative statements that are better?

Answered: 1 week ago