File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Printing out the contents of an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Printing out the contents of an array" Watch "Printing out the contents of an array" New topic

Printing out the contents of an array

Paul Roberts

Joined: Sep 26, 2011
Posts: 11
I am working my way through and java tutorial and have come across some code which is supposed to be a simple method for printing

out the contents of an array. Unfortunately I can't work out how to use it. When I try to add it to the main method I get this error

message when compiling. 'illegal start of expression'

The code is:

Some guidance on how to incorporate static void printLargestAndSmallestElements (int[] n) would be most helpful
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

i've added code tags to make your post easier to read. next time, just highlight your java and click the little "code" button above, just like you wanted to make it bold or italic.

I didn't really look at this code to see if it works or not. My GUESS is that the code is probably fine, but that you are not putting it in the correct spot. You need to be sure it is not inside another method, but that it is inside the class itself. Proper formatting makes it easier to tell. But basically, your code should be structured something like
public class MyClass

if you can't figure it out, paste all your source here, as the problem is probably not in this sample

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Paul Roberts

Joined: Sep 26, 2011
Posts: 11
Thanks for the reply, seems I was nearly doing the right thing. I'm not getting any compile errors now however I'm not getting

anything printed out when I run the program. I'll soldier on with that as It must be something fairly straightforward I'm doing wrong.

I agree. Here's the link:
subject: Printing out the contents of an array
It's not a secret anymore!