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

The Archive Base Latest Questions

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

while using hashmap for finding the most common value the code is doing well

  • 0

while using hashmap for finding the most common value the code is doing well if the entered data set contains repeating value on the other hand if the data set has no repeating value it is also returning mode value in that case too 🙁

I want to return that no mode is available .
please help

    public void onMode(View Button){

    EditText inp = (EditText) findViewById(R.id.EditText01);
    float[] input = new float[uno];
    float answer = 0;
    input = points;
    answer = getMode(input);

    Float floatInput2 = new Float (answer);
    String newinput2 = floatInput2.toString();

    inp.setText("Your required Mode is "+newinput2);

}
public static float getMode(float[] values) {
      HashMap<Float,Float> freqs = new HashMap<Float,Float>();

      for (float val : values) {
        Float freq = freqs.get(val);
        freqs.put(val, (freq == null ? 1 : freq+1));
      }

      float mode = 0;
      float maxFreq = 0;

      for (Map.Entry<Float,Float> entry : freqs.entrySet()) {
        float freq = entry.getValue();
        if (freq > maxFreq) {
          maxFreq = freq;
          mode = entry.getKey();
        }
      }

      return mode;
    }

I want to find the most repetitive value in the data set or if data set don’t contains any repeating value then it will return “no mode exist”

  • 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-27T06:08:42+00:00Added an answer on May 27, 2026 at 6:08 am

    Your getMode function will need to have some means of returning that “no mode exists”. That means you will need to have some special value to represent not having a mode. You can use any value outside of the range of legal values to be returned, but I recommend (and I think most would agree with me) that null is the best value to signify that. In order to return null, you will need to modify your getMode to return a Float rather than a float.

    public void onMode(View Button){
      EditText inp = (EditText) findViewById(R.id.EditText01);
      float[] input = new float[uno];
      input = points;
    
      Float floatInput2 = getMode(input);
      String newinput2 = floatInput2.toString();
    
      if (floatInput2 != null) {
        inp.setText("Your required Mode is "+newinput2);
      } else {
        inp.setText("No mode was found.");
      }
    }
    
    public static Float getMode(float[] values) {
      HashMap<Float,Float> freqs = new HashMap<Float,Float>();
    
      for (float val : values) {
        Float freq = freqs.get(val);
        freqs.put(val, (freq == null ? 1 : freq+1));
      }
    
      float mode = 0;
      float maxFreq = 0;
    
      for (Map.Entry<Float,Float> entry : freqs.entrySet()) {
        float freq = entry.getValue();
        if (freq > maxFreq) {
          maxFreq = freq;
          mode = entry.getKey();
        }
      }
    
      if (maxFreq > 1) {
        return mode;
      } else {
        return null;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ghc 6.12.2 and the latest Data.HashMap 1.1.0 package, and while compiling with
In java while using the HashMap, they are using the Iterator class. But I
While using Vim (at home and at work), I often find myself doing similar
I am trying to parse a hashmap that contains name-value pairs... The entities stored
Here is my code to store the data into HashMap and display the data
While using Struts2, I am using several annotations to do my validations inside the
While using regex to help solve a problem in the Python Challenge , I
While using the vector why do we sometime use the operator[] like homework[mid] but
While using Aptana and Eclipse for the first time in my programming life for
While using fixed width select tag , there is one bug in IE. When

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.