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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:45:47+00:00 2026-05-30T07:45:47+00:00

Today in the class of Java the professor came up with this example but

  • 0

Today in the class of Java the professor came up with this example but I really couldn’t understand very well the process how to go through this method in order to get the result = 4. Could any body please put some lines as clear as possible how is that this method is solved?? Thank you
Ok so this is the method:

public static int mystery(int[] values, int start, int value)
{
    if(start == values.length) {
        return value;
    }
    else
        return Math.max(value, mystery(values, start+1, values[start]));
}
  • 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-30T07:45:49+00:00Added an answer on May 30, 2026 at 7:45 am

    The result isn’t 4, but the maximum in the array.

    It goes like this:

    values is the array of elements.

    start is the current index.

    value is the current maximum.

    If the current index is past the length of the array, return the current maximum. This is the first line of code and the halting condition.

    Otherwise, return the maximum between the current maximum and the maximum of the array past the current index. Which will, recursively, ultimately return the maximum in the array.

    You initially call this function with start = 0 and value = 0.

    Assume values = [2,5,1].

    mystery ( [2,5,1], 0 , 0 ) ->
      start (0) != values.length (3) ->
      return max (0, mystery( [2,5,1], 1, 2 ) ->
          mystery ( [2,5,1], 1, 2 ) ->
            start (1) != values.length ->
            return max (2, mystery( [2,5,1], 2, 5 ) ->
                mystery ([2,5,1], 2, 5) ->
                start(2) != values.length ->
                    return max(5, mystery( [2,5,1], 3, 2) ->
                       start(3) == values.length ->
                       return value (1)
                    -> return max(5,1)
                -> return 5
             -> return max(2,5)
           -> return 5
       -> return max(0,5)
    -> return 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a student in Java class and learned something about Java today that made
I'm really stumped on this issue. I have a problem where Java can't find
In class today, my professor was discussing how to structure a class. The course
My java class (servlet) has been running fine, but recently, I noticed a problem.
A coworker (who is very new to Java) stopped in today and asked what
Is there a Java equivalent of DateTime.MinValue and DateTime.Today in the Java Date class?
I have learned that we can't instantiate an abstract class. But today i tested
I have never used DBIx::Class until today, so I'm completely new at it. I'm
I noticed some code of a colleague today that initialized class variables in the
Today when I was in computer organization class, teacher talked about something interesting to

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.