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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:19:51+00:00 2026-05-25T11:19:51+00:00

I am trying to code a frequency analysis program for fun. I currently have

  • 0

I am trying to code a frequency analysis program for fun. I currently have everything being stored in a hashmap and I index the values using an iterator.

My values however are stored as integers, how could I go about converting these entries into percentages, or a more accessible format so i can compare them later?

I was thinking i could use getValue(), but this is an object.

Can anyone point me in the right direction? Should i be using a hashmap? should i transfer them into an array the size of the hashmap?

  • 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-25T11:19:52+00:00Added an answer on May 25, 2026 at 11:19 am

    Hashmaps are indeed ideal for building freuqency tables, and the value type should definitely be Integer (if you try to store percentages, you’d have to update all percentages each time you add a new value). If you have another class that contains the hashmap as a field, you could make a method for retrieving the percentage of a specific character (note that I don’t recall the exact method names):

    public float getPercentage(char c) {
        if (!map.containsKey(c))
            return 0;
        int sum = 0;
        for (Integer count : map.values())
            sum += count;
        return map.get(c) / (float)sum;
    }
    

    If you want the percentages for all characters, you should make a method that produces a new hashmap that contains the percentages, calculated in a similar fashion. If you want to be fancy (read: overengineer), you could even implement an Iterator that produces percentages from the original Integer hashmap.

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

Sidebar

Related Questions

I am trying to write a program wit Perl which should returns the frequency
When trying code that looks like this, mainly for testing NSInvocationOperation *operation = [NSInvocationOperation
I am trying to code this from scratch, so that when a button clicked
I am trying to code simple membership class. First class name is Customer and
I am writing a program to control a flashbulb. The flash fires in response
I'm trying to add support for tracking application usage to a WP7 app (e.g.,
I'm trying to write my flex application so that it restores the user's settings
i was trying to animate the UIActivityindicator at didSelectRowAtIndexPath i.e when row is selected
It seems like this question gets asked frequently, but having looked through all of
I'm writing a 3D model viewer application as a hobby project, and also as

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.