# 2 dime array with following methods

Show 40 post(s) from this thread on one page
Page 2 of 2 First 12
• March 2nd, 2013, 01:19 PM
Norm
Re: 2 dime array with following methods
I think the two dim array is confusing you. To learn how to use arrays and the indexes to arrays, try writing a simpler program. Write a new program that defines a short (3 element) array. Write a loop to find the smallest element in the array and print out its index after the loop that looks through the elements in the array. That should be a short simple program to show you how to remember the index to the smallest element in the array. It will be simpler than working with a two dim array.
• March 2nd, 2013, 01:22 PM
mikeymike
Re: 2 dime array with following methods
Code java:

```public class smallestIndex1 { public static void main( String [] args ) { //declare and instantiate the array int [] smallestIndex = { 13,11,12,10,14,15 } ;   int min = 0;   for ( int i =1; i < smallestIndex.length; i++ ) { if ( smallestIndex[i] < smallestIndex[min] ) min = i; }   System.out.println( " The smallest int appeared at index >" + min );   } }```
like this?
• March 2nd, 2013, 01:27 PM
Norm
Re: 2 dime array with following methods
Did that code work? It looks like it could.

If it works, then consider what changing the array to two dimensions will do to the coding.
• March 2nd, 2013, 01:36 PM
mikeymike
Re: 2 dime array with following methods
yea that code works and i guess thats my problem once the seconds dimension is added i cant seem to figure it out

--- Update ---

besides add the aspect of [j] i guess
• March 2nd, 2013, 01:43 PM
Norm
Re: 2 dime array with following methods
Change the code in the test program to use a 2 dim array with data in the second row:
Code :

` int [][] smallestIndex = {{1}, {13,11,12,10,14,15 }} ;`
Then change the loop to search the data in the second row
• March 2nd, 2013, 02:00 PM
mikeymike
Re: 2 dime array with following methods
then it just goes back to saying
smallestIndex1.java:17: error: bad operand types for binary operator '<'
• March 2nd, 2013, 02:04 PM
Norm
Re: 2 dime array with following methods
Two dim arrays require two indexes.
The first index will be for the second row where the data to be searched is: [1]
The second index will be the looping index:i or the min variable pointing to the smallest found so far.

Also posted at: http://forums.devshed.com/java-help-...ml#post2861394
Show 40 post(s) from this thread on one page
Page 2 of 2 First 12