Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing out the contents of an array

 
Paul Roberts
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 12180
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Roberts
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic