Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Random; public class RuntimeAnalyzer { public static void main ( String [ ] args ) { int totalTime = 0 ; int totalAssignmentStatement =

import java.util.Random;
public class RuntimeAnalyzer {
public static void main(String[] args)
{
int totalTime =0;
int totalAssignmentStatement =0;
long startTime;
long stopTime;
for (int arraySize =5; arraySize <51; arraySize +=5){
for (int i =1; i <=20; i++){
startTime = System.nanoTime();
totalAssignmentStatement += MethodTester.algorithm1(GenerateArray(arraySize));
stopTime = System.nanoTime();
totalTime +=(stopTime - startTime);
}
System.out.println("=Array size "+ arraySize +"=
average assignment statements: "+ totalAssignmentStatement /20.0+
"
Average execution time: "+ totalTime/20.0+"ns ("+ totalTime /20.0/1000000.0+"ms)
");
totalTime=0;
totalAssignmentStatement=0;
}
}
public static int[] GenerateArray (int arraySize)
{
int[] array = new int[arraySize];
//TODO
return array;
}
}

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

More Books

Students also viewed these Databases questions

Question

1. Describe the power of nonverbal communication

Answered: 1 week ago