• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

2d arrays help

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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, https://coderanch.com/t/503889/java/java/Printing-primitive-array
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic