Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7502861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:01:14+00:00 2026-05-29T21:01:14+00:00

I am currently attempting to revise a Java Homework program for my Data Structures

  • 0

I am currently attempting to revise a Java Homework program for my Data Structures class that displays the output of the MaxSumTest program in a table.

I’ve created four arrays, and placed them inside one of the loops that calculates the timing info. I am trying to populate each array with only the timing info for one algorithm. So each array would have 4 elements. However, every time I run my revision of the program, I get an out of bounds error.

Here is the Original

The only method I revised is getTimingInfo. Here is my revision:

public static void getTimingInfo( int n, int alg )
{
    int [] test = new int[ n ];

    long startTime = System.currentTimeMillis( );;
    long totalTime = 0;



   //create an array for each Algorithm
    long[] alg4;
    long[] alg3;
    long[] alg2;
    long[] alg1;

    //allocate memory for 5 long ints 

    alg4 = new long[5];
    alg3 = new long[5];
    alg2 = new long[5];
    alg1 = new long[5];

   int i;
   int j;
   int index = 0;

   for( i = 0; totalTime < 4000; i++ )
   {
       for( j = 0; j < test.length; j++ )
           test[ j ] = rand.nextInt( 100 ) - 50;
    index = j;
       switch( alg )
       {
         case 1:
           maxSubSum1( test );
           break;
         case 2:
           maxSubSum2( test );
           break;
         case 3:
           maxSubSum3( test );
           break;
         case 4:
           maxSubSum4( test );
           break;
       }

       totalTime = System.currentTimeMillis( ) - startTime;

   }

    alg1[index] = totalTime * 1000 / i;
    alg2[index] = totalTime * 1000 / i;
    alg3[index] = totalTime * 1000 / i;
    alg4[index] = totalTime * 1000 / i;

    //Build first column of table
    System.out.println("Size of N Algorithms\t" + "250\t" + "2500\t" + "25000\t" + "250000");

    System.out.println("Alg #4\t" + alg4[0] + "\t" + alg4[1] + "\t" + alg4[2] + "\t" + alg4[3] + "\t" + alg4[4]);
    System.out.println("Alg #3\t" + alg3[0] + "\t" + alg3[1] + "\t" + alg3[2] + "\t" + alg3[3] + "\t" + alg3[4]);
    System.out.println("Alg #2\t" + alg2[0] + "\t" + alg2[1] + "\t" + alg2[2] + "\t" + alg2[3] + "\t" + alg2[4]);
    System.out.println("Alg #1\t" + alg1[0] + "\t" + alg1[1] + "\t" + alg1[2] + "\t" + alg1[3] + "\t" + alg1[4]);


    /*

    System.out.println( "Algorithm #" + alg + "\t"
         + "N = " + test.length
         + "\ttime = " + ( totalTime * 1000 / i ) + " microsec" );
    */


 }

Any advice or pointers in the right direction would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:01:15+00:00Added an answer on May 29, 2026 at 9:01 pm

    I’m not sure exactly what you are trying to do, but I think that what you really want to do is call getTimingInfo() a number of times and then assign the results to a table, not change the internal workings of getTimingInfo().

    This requires that you define the arrays in which you will store the timing data OUTSIDE of getTimingInfo(), and then the only change inside of getTimingInfo() would be storing to that (already defined) array, rather than printing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently attempting to write my own program that mirrors the pmap command, specifically
I'm currently attempting to port a Java program over to iOs which utilzes BufferedImage's
I am currently attempting to implement a custom gridview interface to display data from
I am currently attempting to use Lucene to search data populated in an index.
I'm attempting to create Data Access Layer for my web application. Currently, all datatables
I'm currently attempting to use the Windows Powerpack DataRepeater control to display data from
I am currently attempting to build a web application that relies quite heavily on
I'm attempting to execute a batch script that currently looks like this: D: cd
I am currently working on a script that I am attempting to automate via
I am currently attempting to find a suitable xpath that will help me validate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.