Karl Beaudry wrote:I can't figure out how or where i need to add the day part into the code so when the max or min loop back in to find the values it will also remember the day that it found it on.
Karl Beaudry wrote:So to answer a few questions. Basically what I am asking is when my code searches and finds the max and min value, I need it to store the day that it found the value on. So if the max is 73 on day 344, its already finding the max 73 but its not storing the day 344. Basically because I don't have that part written into it. I guess i can do an index, but would that be a whole new variable and initialized as well and then link it to the max and min array respectively. So could I set an index and grab the value (max or min) from the index, is that what you are saying.
Line 32 is different from line 22. When i set line 32 to a 0 (same as line 22), the min output is always zero, so i had to set it to 1. But i should have set line 22 to 1 as well, so i fixed that.
Junilu Lacar wrote:
Line 32 is different from line 22. When i set line 32 to a 0 (same as line 22), the min output is always zero, so i had to set it to 1. But i should have set line 22 to 1 as well, so i fixed that.
That would be wrong. Just try putting an very large number or very small number in element[0] and you will see why. You need to start with the assumption that the first element (index == 0) is the smallest/largest value in the array. Then as you iterate the array, correct that assumption when appropriate. So you need to initialize your min/max variable to array[0] before you go into the for-loop.
Carey Brown wrote:
Normally I'd agree with you that index 0 is the way to go, however Karl has implemented an array where data starts at index 1. I might suggest to Karl that he refactor the code at some point so that the whole thing is based from index of 0 to 364.
I hope I have some readersA few minutes ago, I wrote: . . . my regular readers . . .
Campbell Ritchie wrote:If you pass an empty array you get an Exception. Only works in Java8.
System.out.println(Arrays.stream(myArray).max.getAsInt());
Campbell Ritchie wrote:I hope I have some readers
luck, db
There are no new questions, but there may be new answers.
Karl Beaudry wrote:Here was the cleaned up version minus the indexing. If you have any pointers to actually make it look cleaner, or flow better let me know.
Karl Beaudry wrote:I know one of the biggest issues the guys I work with tell me is to make sure it flows and cleans up well, plus document document document on changes and methods.
Never knew about that. Thank you But wouldn't you pass Integer.MIN_VALUE as an argument to that method?Darryl Burke wrote: . . .
Pass an empty array and return 0, not get an Exception:
Thank youCampbell Ritchie wrote:I hope I have some readers
I can vouch foir one
Campbell Ritchie wrote:wouldn't you pass Integer.MIN_VALUE as an argument to that method?
luck, db
There are no new questions, but there may be new answers.
Karl Beaudry wrote:I understand the concept and what i needed to do, just actually implementing it into the code just was not working for me, probably cause I am trying to implement it after the fact and im learning which usually doesn't mix. I tried different methods, and using different variables to track the day, but it continuously gave me wrong results, or wouldn't compile.
Carey Brown wrote:... Karl has implemented an array where data starts at index 1. I might suggest to Karl that he refactor the code at some point so that the whole thing is based from index of 0 to 364.
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|