Paul Clapham wrote:Your problem occurs because you used "pos++" instead of "++pos".
If you come back to that code late in the Summer and have forgotten what it is supposed to do, then bad variable names will make the code much more difficult to understand. It will have become quite a large detail in six months.Liutauras Vilda wrote:. . . those are quite small details . . .
Junilu Lacar wrote:What does your very first call to this method look like? Is the second argument you pass the length of the array?
Paul Clapham wrote:Your problem occurs because you used "pos++" instead of "++pos".
Liutauras Vilda wrote:I find confusing variable name 'compare'. Might it just me...
Recaip Sanli wrote:
Math.max is part of java.lang package, that means it is imported automatically without asking your or your teacher's permission. Anyway, while Math.max could have its use here, I don't think it is crucial.Recaip Sanli wrote:So many approaches including Math.max won't work because I am not suppose to import anything.
Liutauras Vilda wrote:
Math.max is part of java.lang package, that means it is imported automatically without asking your or your teacher's permission. Anyway, while Math.max could have its use here, I don't think it is crucial.Recaip Sanli wrote:So many approaches including Math.max won't work because I am not suppose to import anything.
Having said that, can you give us exact requirements? So we wouldn't give you hints which aren't permitted based on the given instructions.
In the RecursiveMethods class, you are required to implement the following methods using
recursive solutions (no looping statements):
largestRec(int[] arr, int pos) – This method takes an integer array as well as an
integer (the starting index) and returns the largest number in the array.
Recaip Sanli wrote:
Requirement says this:In the RecursiveMethods class, you are required to implement the following methods using recursive solutions (no looping statements):
largestRec(int[] arr, int pos) – This method takes an integer array as well as an integer (the starting index) and returns the largest number in the array.
Recaip Sanli wrote:
Paul Clapham wrote:Your problem occurs because you used "pos++" instead of "++pos".
Well good catch, I changed that and now it runs but only 2 cases true, the rest false.
Paul Clapham wrote:My personal practice is to never use either x++ or ++x except in the well-known idiom "for (int i=0; i<something; i++)". It's just too much trouble to bother remembering which does pre-increment and which does post-increment, especially since "x = x+1" is easier to understand anyway.>
Recaip Sanli wrote:So many approaches including Math.max won't work because I am not suppose to import anything.
Recaip Sanli wrote:Good news, I came up with super compact answer
Liutauras Vilda wrote:Just double check with your instructor you are finally allowed to use that Math.max()
Recaip Sanli wrote:So many approaches including Math.max won't work because I am not suppose to import anything.
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|