Results 1 to 4 of 4
- 01-30-2011, 08:29 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 78
- Rep Power
- 0
How can i remove a value from an array?
i have a program with several methods. it inserts about 10 elements.
i find the maxvalue with this method
with this callJava Code:public long getMax() { if (nElems != 0) { long maxValue = a[0]; for (int index = 1; index < a.length; index++) { if (a[index] > maxValue) { maxValue = a[index]; } } return maxValue; } else { return -1; } }
i need to make a remove method that takes that maxvalue and removes it. but i cant figure out how to do it.Java Code:maxValue = arr.getMax(); System.out.println("The highest value in the array is " + maxValue);
- 01-30-2011, 08:50 PM #2
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Traverse the array again and when it finds the highest value set it to zero?
Is that what you want?Java Code:public void removeMax() { for (int i = 0; i < a.length; i++) { if (a[i] == maxValue) a[i] = 0; } }
- 01-30-2011, 09:00 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 78
- Rep Power
- 0
idk. it doesnt work because it cant find maxValue. and when i try to fiddle around i keep getting missing identifier.
- 01-30-2011, 09:31 PM #4
Last edited by j2me64; 01-31-2011 at 11:06 AM.
Similar Threads
-
Remove .0
By maple_leafs182 in forum New To JavaReplies: 4Last Post: 01-28-2011, 02:47 AM -
How do I remove objects from an Array in java?
By hamed in forum New To JavaReplies: 3Last Post: 09-08-2010, 01:20 PM -
how to remove an object from the array list
By cecily in forum New To JavaReplies: 3Last Post: 08-02-2007, 02:26 PM -
Remove the bucket represented by the int from array
By barney in forum New To JavaReplies: 1Last Post: 08-01-2007, 08:55 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks