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

  • Home
  • SEARCH
  • 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 7693929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:12:08+00:00 2026-05-31T21:12:08+00:00

I have below five Integer variables and during the program, they are assigned some

  • 0

I have below five Integer variables and during the program, they are assigned some values randomly. I want to get the largest variable name but not the variable value. And I want to know if at least two of them have the same value. Please provide an example. Thank you.

int politics_counter = 0;
        int economics_counter = 0;
        int foreign_counter = 0;
        int sport_counter = 0;
        int weather_counter = 0;
  • 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-31T21:12:09+00:00Added an answer on May 31, 2026 at 9:12 pm

    And now for an answer (kind of)

    public class MyThingie {
    
    TreeMap<Integer, String> data = new TreeMap<Integer, String>();
    
    public void doIt() {
        ...
    
        insertElement("politics_counter", politics_counter);
        insertElement("economics_counter", economics_counter);
        insertElement("foreign_counter", foreign_counter);
        insertElement("sport_counter", sport_counter);
        insertElement("weather_counter", weather_counter);
    
        System.out.println("Highest variable is "+data.lastEntry().getValue());
    }
    
    public void insertElement(String name, Integer i) {
        if (data.get(i) == null) {
            System.out.println("Element "+name+" has the name value as "+data.get(i));
        }
        else {
            data.put(name,i);
        }
    }
    }
    

    and now for a more interesting answer:

    public class BiggestFinder {
        public void showBiggester(Object o) throws Exception {
            TreeMap<Integer, String> data = new TreeMap<Integer, String)();
            for (Field f  : o.getDeclaredFields()) {
                Object v = f.getValue(o);
                if (v instanceof Integer) {
                    if (data.get(v)!=null) {
                        System.out.println("Value for "+f.getName()+" is the same as "+data.get(v));
                    }
                    else {
                        data.put((Integer)f.getValue(o), f.getName());
                    }
                }
            }
    
            System.out.println("Largest is "+data.lastEntry().getValue());
        }
    }
    

    which will interrogate an object and show the largest field, given that the object has members that are all Integers and that are all accessible to this method. There’s a way to fudge that and improve it to make it more “robust”.

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

Sidebar

Related Questions

I have an array below, var array = { Id:[1,2,3], Name:[one,two,five], row:[8,9,7] } but
I have a code residing on server which contain 5 attribute values assigned from
I have a large function (I know, see below) that breaks proguard during its
I have a list items as below and i want to hide the children
I have the below HTML structure: <ul> <li><a>one</a></li> <li><a>two</a></li> <li></li> <li><a>three</a></li> <li><a>four</a></li> <li></li> <li><a>five</a></li>
I have below a list of text, it is from a popular online game
I have below html code in my aspx. <input type=hidden id=medicalLink value='<a href=/forms/contactus.aspx >Contact
I have below query I am trying to show message 'No SubSource for this
I have below trigger ALTER TRIGGER [dbo].[DeleteUserData] ON [dbo].[site_users] AFTER DELETE AS BEGIN SET
I have below code in html. <li class=selected runat=server id=lihome><a href=/ISS/home.aspx title=Home><span>Home</span></a></li> Now I

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.