permaculture playing cards*
The moose likes Beginning Java and the fly likes Printing an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Printing an array" Watch "Printing an array" New topic
Author

Printing an array

Mike Johnston
Greenhorn

Joined: Jan 17, 2012
Posts: 11
Hi,

I'm having some trouble with an assignment of mine when it comes to the printing out the sorted array part of the assignment. (Lines 95-98 specifically, although my problem may be coming from another location. This section was just the default code that was provided already.)

I have a feeling it may have something to do with my array I created in trying to print it. How ever I have tried lots of different things like but I have a feeling this is totally the wrong direction to go.

Still a beginner to all of this and some help would be awesome.

It compiles and runs with it commented out so I know the other classes are fine.


Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Mike Johnston wrote:
I'm having some trouble with an assignment of mine when it comes to the printing out the sorted array part of the assignment


Exactly what kind of trouble? You'll find that people are better able to help you if you TellTheDetails.(⇐click)
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7081
    
  16

Mike Johnston wrote:I have a feeling it may have something to do with my array I created in trying to print it. How ever I have tried lots of different things like but I have a feeling this is totally the wrong direction to go.

Still a beginner to all of this and some help would be awesome.

Every class has a toString() method that you are allowed to redefine. I'd suggest you start there.

Implement this method for each of your Shape classes in the form that you want, and then do something like:

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
Mike Johnston
Greenhorn

Joined: Jan 17, 2012
Posts: 11
Oops sorry.. I thought I had included my error.. Basically I'm getting



when I try and compile it (that is with line 95 uncommented and the others commented. I can't seem to find out why I can't find variable"r" (I'm assuming because variable"r" is saved into the array).
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Mike Johnston wrote:I can't seem to find out why I can't find variable"r"


Because you haven't defined any such variable in that scope.

Also, one-letter variable names for just about anything other than loop indices are evil.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing an array
 
Similar Threads
Generic methods and wildcards
Calling methods using dynamic binding
Runtime and compile-time ?
the instance variable shapes
Help with Value Returning Methods