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 6940045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:42:12+00:00 2026-05-27T12:42:12+00:00

Basically, I have an assignment that requires me to find the mode of a

  • 0

Basically, I have an assignment that requires me to find the mode of a given set of numbers.

This is my Method:

 public void findMode (){
  /* The vector data is analyzed and transferred into a smaller vector
    smallList (0..100).  For each occurrence of n in vector data,
    smallList[n] is incremented +1.  function Largest is then called
    to find the largest quantity in vector smallList.  The mode(s)
    is/are printed out. */

    int loop, largest;
    int[] smallList = new int[101];    
    for (int i = 0; i < myHowMany; i++)
    {
        smallList[myData[i]]++;
    }
    int max = 0;
    for (int i = 0; i < smallList.length; i++)
    {
        if (max < smallList[i]) 
        {
            max = smallList[i];
        }
    }
//Max is 26
    int size = 0;
    for (int i = 0; i < smallList.length; i++)
    {
        if (i == max) size++;
    }

    int[] modes = new int[size];
    int modeIndex = 0;
    for (int i = 0; i < smallList.length; i++)
    {
        if (smallList[i] == max) 
        {
            modes[modeIndex] = smallList[i];
            System.out.println(modes[modeIndex]);
            modeIndex++;
        }
    } Everything compiles fine, but when I run this method, I get an out of bounds array method. I have no idea WHY this happens so I

need to know if the community can help me

.
Solved!

Please tell me if I need more information!

edit: I forgot to mention that I get the error here:

modes[modeIndex] = smallList[i];

New Problem:
I fixed the problem from before, but now, I find that my max goes unto the array so that modes = 26(max)

  • 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-27T12:42:13+00:00Added an answer on May 27, 2026 at 12:42 pm

    Your error is in this line

    if (i == max) size++;
    

    It should be

    if (smallList[i] == max) size++;
    

    This is causing the size of modes to be wrong

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

Sidebar

Related Questions

I basically, for this assignment, have to make a mini-program that randomly generates a
I have an assignment to find the minimum, maximum, and average of numbers that
So, a long story short, I have a Java homework assignment that requires a
I have a simple assignment that the professor wants us to do. Basically to
I have this school assignment that I've been working on and am totally stumped
I basically have a program that filters records from one excel file to another
I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
I basically have 7 select statements that I need to have the results output
I basically have to do a update of a record. I have a set

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.