Java Help

Xylitol

Diamond Member
Aug 28, 2005
6,617
0
76
double result = array[0];
for(int i = 1; i > array.length; i++)
if(array < result)
result = array;
return result;

Will this give me the maximum value in the array?
And how would I find the INDEX of the max/min?
findIndex is only for strings

Edit: Does everything look italicized for some weird reason on this post only?
 

Xylitol

Diamond Member
Aug 28, 2005
6,617
0
76
Originally posted by: flashbacck
What's your reasoning for comparing array[i ] with array[i+count]?

I wanted the previous element to compare to the other
I know that this isn't a direction I should be going in, but I couldn't think of another way.

Thanks HigherGrounds by the way
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81

Edit: Does everything look italicized for some weird reason on this post only?

Bracketed 'i' indicates start of italics.

You can use the 'break' keyword to force yourself out of a loop in progress. That's not terribly useful here; instead add another variable to keep track of the index value of the array minimum.
 

Xylitol

Diamond Member
Aug 28, 2005
6,617
0
76
Originally posted by: diegoalcatraz

Edit: Does everything look italicized for some weird reason on this post only?

Bracketed 'i' indicates start of italics.

You can use the 'break' keyword to force yourself out of a loop in progress. That's not terribly useful here; instead add another variable to keep track of the index value of the array minimum.

Yes but how would I structure that. I looked in my textbook "Big Java" and can't find anything on how to find the index of something in an array
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
For your code, you have a variable that stores the minimum value of the array, correct? Declare another one, as an integer, which will store the index of the minimum value. You're iterating through the array by 'i', which represents the current index. When you find a new minimum value, store i into your new variable. You can even omit the first variable (for minimum), since after running through your loop array[minimumIndex] would return your minimum value.
 

duragezic

Lifer
Oct 11, 1999
11,234
4
81
1) Use the 'Attach code' feature. So many 'do my homework posts' that don't even use this feature. As it is now, you were given perfectly working code for minimum except by not using Attach code it looks like your code is wrong and thus the italicized text.
2) You were given the find minimum by someone, but you can't think of how to find the maximum? From a correctly working minimum it would require a single character change. Surely you can figure that out. Are you even trying to think about each line means?

As far as finding the index instead of the actual value, the int i in your for loop represents the current index you are checking. That should make it very obvious to save this index value instead of the double value in array{i}
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: duragezic
2) You were given the find minimum by someone, but you can't think of how to find the maximum? From a correctly working minimum it would require a single character change. Surely you can figure that out. Are you even trying to think about each line means?
QFT. This is getting ridiculous. We need a software mod who just shuts down "do my homework" questions. Otherwise we'll end up with a generation of aters who passed all their courses but simply don't know how to code :p