Results 1 to 2 of 2
- 02-20-2011, 01:47 AM #1
Member
- Join Date
- Nov 2009
- Location
- Honolulu, HI
- Posts
- 50
- Rep Power
- 0
Finding the Smallest Element in an Array
I'm trying to write a portion of code to find the smallest element of an array. The code below works; however, it doesn't place a negative symbol in front of the element (if its negative). For example, if the smallest element is -2, my code returns "2".
Any guidance is greatly appreciated.Java Code:int minIndex = 0; for (int i = 1; i < a.length; i++) { if (a[minIndex] > a[i]) minIndex = i; }Last edited by Cod; 02-20-2011 at 02:31 AM.
- 02-20-2011, 02:05 AM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
Similar Threads
-
Problem getting numbers from user and finding smallest two numbers
By radhi16 in forum New To JavaReplies: 11Last Post: 01-14-2011, 06:36 PM -
Array[] get smallest/largest value
By bobocheez in forum New To JavaReplies: 13Last Post: 09-09-2010, 11:16 PM -
Trying to make an array list // inserting an element to middle of array
By javanew in forum New To JavaReplies: 2Last Post: 09-06-2010, 01:03 AM -
Problem with finding the max element
By SMHouston in forum New To JavaReplies: 39Last Post: 09-13-2009, 10:34 PM -
Finding largest and smallest integer
By mlhazan in forum New To JavaReplies: 2Last Post: 01-12-2008, 10:30 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks