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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:44:06+00:00 2026-06-12T01:44:06+00:00

I need to write my own function that returns the most repeated value of

  • 0

I need to write my own function that returns the most repeated value of the array.
I have an array, and I need to count statistical fashion (mode, which is the most repeated value in array) and I don’t know why it’s not working.

I create 2 arrays:

The first contains the values, and the second array I want to insert how many times each value from first array are repeated, then by my function, findmax, I search for the biggest index of repeated value, and then finally show a message with the mode.

public int findmax(Integer [] somearray) { 
    int max = somearray[0];
    int z=0;

    for (int i = 0; i < somearray.length; i++) {
        if (somearray[i]>max){
            max = somearray[i];
            z = i;
        }
    }        

    return z;
}

private void myModaActionPerformed(java.awt.event.ActionEvent evt) {
    Double [] myarray = new Double[dsTable.getRowCount()];
    Integer [] myarray2 = new Integer[dsTable.getRowCount()];

    for (int i=0; i < myarray.length; i++){
        myarray[i] = (Double)dsTable.getModel().getValueAt(i, 0);
    }

    java.util.Arrays.sort(myarray);
    for (int i = 0; i < myarray.length; i++){
        JOptionPane.showMessageDialog(this.mainPanel,((Double)myarray[i]));
    }
    for (int i = 0; i < myarray2.length; i++){
        myarray2[i]=0;
    }
    for (int i = 0; i < myarray.length; i++){
        for (int j = 0; j < myarray.length; j++){
            if (myarray[i] == myarray[j]){
                myarray2[i]++;
            }
        }  
    }
  JOptionPane.showMessageDialog(this.mainPanel,myarray[findmax(myarray2)]);              
}

The result of program is first value of the first array.

  • 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-06-12T01:44:08+00:00Added an answer on June 12, 2026 at 1:44 am

    Seems like your homework, so I’ll give you some pointers to help you out.

    • Consider using a HashMap. Here the key would be numbers in your first array and value would be count for each value that you encounter. So the first time you encounter a number, add it to the map, and for every subsequent time, you just increment the value

    • Once you’ve this map, it would be trivial to find out the key which has the maximum value. Also note that there might be more than one key that can have that maximal value, so you might want to handle that case as well.

    One more hint: The way you’re incrementing your second array seems incorrect. You might want to revisit your logic over there as well.

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

Sidebar

Related Questions

I need to write a C++ code coverage program that takes in another C++
I need to write a program that prints 0.(03) for input 1 and 33.
I need to write to a text file using JavaScript. I have a machine
I need to write the output of the code I have to a file
i need to detect when some third party function returns and then execute my
Let's say I have an array that looks like this: $array[0] = 'House'; $array[1]
Is it possible to write code that wrap any node.js i/o-callback with my own
Let's say that for some reason you need to write a macro: MACRO(X,Y) .
I'm new to erlang. I wonder how to write a function which returns the
I need to write my own memory allocation functions for the GMP library, since

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.