Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 32 of 32

Thread: 2 dime array with following methods

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Junior Member
    Join Date
    Feb 2013
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 2 dime array with following methods

    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?

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Junior Member
    Join Date
    Feb 2013
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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:
    	int [][] smallestIndex = {{1},  {13,11,12,10,14,15 }} ;
    Then change the loop to search the data in the second row
    If you don't understand my answer, don't ignore it, ask a question.

  6. #31
    Junior Member
    Join Date
    Feb 2013
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 2 dime array with following methods

    then it just goes back to saying
    smallestIndex1.java:17: error: bad operand types for binary operator '<'

  7. #32
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 2
    Last Post: January 14th, 2013, 03:22 PM
  2. Why and where abstract methods & classes and static methods are used?
    By ajaysharma in forum Object Oriented Programming
    Replies: 7
    Last Post: July 14th, 2012, 01:16 AM
  3. Needing some help with array getter and setter methods!!
    By BlackShadow in forum What's Wrong With My Code?
    Replies: 8
    Last Post: April 5th, 2012, 07:11 PM
  4. I need help with my methods please?
    By THeAnnonymous in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 11th, 2011, 09:22 AM
  5. Grade averaging program with array and multiple methods.
    By jeremykatz in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 9th, 2009, 09:44 PM