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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:02:28+00:00 2026-06-15T10:02:28+00:00

I have a question. I am trying to display the maximum value’s index in

  • 0

I have a question. I am trying to display the maximum value’s index in an array. I was able to obtain the maximum value; however, I don’t know to display the index for that maximum value.

For instance, if index [3] had a value of 5 and were the largest element in an array, it would print:

value[3] = 5 is the largest element

How do I do that?

    import java.util.Scanner;

    public class ArrayExample 
    {
            public static void main(String[] args) 
        {
            //Question 1
            int values[] = new int[5] ;
            System.out.println("Please enter 5 values for this array: ");
            Scanner keyboard = new Scanner(System.in);


              System.out.println("Maximum Value = " + getMaxIndex(values) + getMaxValue(values));  
        }

        public static int getMaxValue(int[] values){  
            int maxValue = values[0];  
            for(int i=0;i<values.length;i++){  
                if(values[i] > maxValue){  
                    maxValue = values[i];  
            }  
            }  
        return maxValue;  
    } 
    public static int getHighestMonth(int[] values) {
            int highest = 0;
            for (int i = 0; i < 5; i++) {
                if (values[i] > values[highest]) {
                    highest = i;
                }
            }
            return highest;
        }

}
  • 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-15T10:02:29+00:00Added an answer on June 15, 2026 at 10:02 am

    You could use AbstractMap.SimpleEntry:

    public static SimpleEntry<Integer, Integer> getMaxValue(int[] values){  
        int maxValue = Integer.MIN_VALUE;
        int maxIndex = -1;
        for(int i=0;i<values.length;i++){  
            if(values[i] >= maxValue){  
                maxValue = values[i];
                maxIndex = i;
            }  
        }
        return new SimpleEntry<Integer, Integer>( maxIndex, maxValue);
    }
    
    public static void main(String[] args) {
        SimpleEntry<Integer, Integer> maxEntry = getMaxValue( new int[]{1,2,3});
    
        System.out.println( "value["+ maxEntry.getKey() + "] = " + maxEntry.getValue() + " is the largest element");
        //value[2] = 3 is the largest element
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display a simple graph using pydot. My question is that
i have a question for you guys. im trying to print an array where
I have a some Chinese characters that I'm trying to display on a Kentico-powered
hello i have this question i was trying to find a way to call
New to Python, have a simple, situational question: Trying to use BeautifulSoup to parse
I have a question about some functionality I'm trying to add to my jQuery
I have a question about reflection I am trying to have some kind of
I have a question related to this one : I'm trying to attach an
I have one question, I was trying to find more information on the internet
i have a question, i am trying this if (strncmp(m_DSServer, TCP:, 4) != 0

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.