Results 1 to 9 of 9
  1. #1
    Spyderpig is offline Member
    Join Date
    Feb 2011
    Posts
    24
    Rep Power
    0

    Default Minimum of 2d Array

    trying to get the minmum of a 2d array... not sure what im doing wrong.



    Java Code:
    	int[][] toReverse = {
    			{11,5,5,5,5},
    			{3,7,8,9,10},
    			{1,2,3,4,5},
    			{1,2,3,4,5},
    			{1,2,3,4,5}
    			};
    	
    	int min = toReverse[0][0];
    	for (int i=0; i<toReverse.length;i++){
    		for(int k=1;k<toReverse.length;k++){
    		if(toReverse[i][k]<min)
    			min=toReverse[i][k];
    		}
    	}
    	System.out.print(min);

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    not sure what im doing wrong
    And neither are we, unless you provide a more detailed description of the problem. Does it compile? Are there exceptions? Does it behave properly?

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default

    Why are you starting k at 1?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Spyderpig is offline Member
    Join Date
    Feb 2011
    Posts
    24
    Rep Power
    0

    Default

    starting at k=1 because i set the min to [0][0] already, which im not sure is right. anyways im trying to get the minimum value of the array which should be 1 but the output is 2.

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default

    Hint- Draw a 2D array, and label the "coordinates" of each index. For example, the coordinates of the index holding the number 10 is [1][4].
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Spyderpig is offline Member
    Join Date
    Feb 2011
    Posts
    24
    Rep Power
    0

    Default

    yea i know how coordinates of arrays work. that doesnt help at all...

  7. #7
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default

    Quote Originally Posted by Spyderpig View Post
    yea i know how coordinates of arrays work. that doesnt help at all...
    Sorry, but if you knew how arrays worked, you wouldn't be having this issue. But if you're unwilling to try some simple advice, I'm not going to waste my time.

    Much luck.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Spyderpig is offline Member
    Join Date
    Feb 2011
    Posts
    24
    Rep Power
    0

    Default

    advice helps people. what you said is the equivalent of saying the world is round. we all know this. thanks for failing.

  9. #9
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default

    Quote Originally Posted by Spyderpig View Post
    advice helps people. what you said is the equivalent of saying the world is round. we all know this. thanks for failing.
    Failing? I'm not the one who can't figure out basic arrays. /immature

    I was perfectly willing to offer you some more hints, had you tried my first one and still not understood what I was getting at. I still think you'd figure it out if you followed my advice.

    Don't worry, I'm sure somebody will eventually come around and spoonfeed you your blatant error. But your terrible attitude and apparent laziness pretty much guarantee a short career in programming.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. minimum,/maximium
    By sinista in forum New To Java
    Replies: 7
    Last Post: 10-01-2009, 05:07 PM
  2. [SOLVED] Help Finding the Minimum value of an array
    By MSteinman in forum New To Java
    Replies: 18
    Last Post: 04-21-2009, 09:14 AM
  3. Help With Minimum Value
    By Bodomar in forum New To Java
    Replies: 1
    Last Post: 11-07-2008, 04:29 AM
  4. To find the Maximum and Minimum in an Array of Strings
    By luscious in forum JavaServer Pages (JSP) and JSTL
    Replies: 9
    Last Post: 07-31-2008, 01:51 PM
  5. Replies: 1
    Last Post: 02-16-2008, 09:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •