GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes 2d arrays help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "2d arrays help" Watch "2d arrays help" New topic
Author

2d arrays help

Joe Howlett
Greenhorn

Joined: Jul 25, 2010
Posts: 2
Hi all.
I need help with my program. Beginning java student here.
I am supposed to create an array by prompting the user for the number of rows and columns.
Then the user is to enter the rows and columns.
At this point, a method is invoked that is to locate the largest element and then return the position of the element in the array.
As far as I can tell, my main method is correct, but I'm having trouble with the other method.
We are to create an array that stores the location of the current largest element.
Could anyone offer any help? After much trial and error, this is the version that shows no red flags in Eclipse, but it's result is this as the location of the largest element "[I@14318bb". I have a feeling this is wrong LOL.




This is the pseudocode we are to follow from my instructor:



// import package for reading keyboard input

// program name
public class LargestElementLocator
{
// program start
public static void main (String [] args)
{
// prompt user for number of rows and columns

// create an empty array based on user input

// for each row

// promt user for row elements

// store elements in appropriate row

// end for

// invoke locateLargest method and store its return values

// display the row an columns of the largest element
// in array based on the values returend by method

}

// locateLargest method
public static int [] locateLargest(double [][] a)
{
// initialize variable largest to 0

// create array b of size 2 to store row and colum of
// largest element in a

// for each row of array a

// for each column of array a

// if element in array a is larger than largest

// store row and column of array a in array b

// end if

// end for

// end for

// return array b
}
}

My apologies for the long post.
Thank you for any advice in advance.
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

You cannot print a primitive array as such using System.out.println().
If you do so, it will return '[' indicating it is an array of 'I' - int type followed by '@' and the hashcode value of the array
Try this, this might help



Dont forget to import Arrays class from java.util package.
Also refer, http://www.coderanch.com/t/503889/java/java/Printing-primitive-array


OCPJP 6
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Cross-posted and answered already here:
http://forums.sun.com/thread.jspa?messageID=11025765

Original poster (OP), please read the FAQ, in particular this one: BeForthrightWhenCrossPostingToOtherSites
Joe Howlett
Greenhorn

Joined: Jul 25, 2010
Posts: 2
Thanks for your reply.
Our instructor said we have to code using just the concepts we've covered so far.
We haven't got that far in the class. I have to evidently keep it more simple than that.
I think I might start from scratch and try to go a simpler route.
You might see me on this board later today! lol
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Joe Howlett wrote:
You might see me on this board later today! lol


That's fine, but again, please be forthright if you cross-post, as we dislike spending our time answering already answered questions as much as the folks in the other fora do.
 
GeeCON Prague 2014
 
subject: 2d arrays help