aspose file tools*
The moose likes Beginning Java and the fly likes array[] [] ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "array[] [] ?" Watch "array[] [] ?" New topic
Author

array[] [] ?

Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

See anything wrong here?



Output: Tool completed with exit code 2


Jon
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660


Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 560
Your line:

int[] [] magicNumbers = new int[] [];

Is an incomplete declaration/creation of the array. Why?


Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4392
    
    8

And:is incorrect - the bit in < > must be a type, not a variable.
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Matthew Brown wrote:And:is incorrect - the bit in < > must be a type, not a variable.





Output
C:\Documents and Settings\Jon\workspace\JavaDev\myCode Snippets\TestSeven.java:15: illegal start of type
for (int x = 0; x < 10; x++)
^
C:\Documents and Settings\Jon\workspace\JavaDev\myCode Snippets\TestSeven.java:15: illegal start of type
for (int x = 0; x < 10; x++)
^
C:\Documents and Settings\Jon\workspace\JavaDev\myCode Snippets\TestSeven.java:15: <identifier> expected
for (int x = 0; x < 10; x++)
^
C:\Documents and Settings\Jon\workspace\JavaDev\myCode Snippets\TestSeven.java:23: illegal start of type
for (int x = 0; x < 10; x++)
^
C:\Documents and Settings\Jon\workspace\JavaDev\myCode Snippets\TestSeven.java:23: illegal start of type
for (int x = 0; x < 10; x++)
^
C:\Documents and Settings\Jon\workspace\JavaDev\myCode Snippets\TestSeven.java:23: <identifier> expected
for (int x = 0; x < 10; x++)
^
6 errors

Tool completed with exit code 1


NOTE: By the way the copy to clipboard option on this forum does not seem to work with my laptop, I am using Google Chrome.

Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 560
An equivalent declaration/creation and initialization of your array would have been:



Did you mean to write your code inside a method? Maybe a main() method? It doesn't have to be main(), but it should be in a method.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14153
    
  18

You cannot put arbitrary statements like "for" at class level. Those statements must be inside a constructor or method.

Jon Camilleri wrote:NOTE: By the way the copy to clipboard option on this forum does not seem to work with my laptop, I am using Google Chrome.

Workaround: Click "view plain" instead of "copy to clipboard", then select the text in the popup window and copy it with Ctrl+C.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Jesper de Jong wrote:You cannot put arbitrary statements like "for" at class level. Those statements must be inside a constructor or method.

Jon Camilleri wrote:NOTE: By the way the copy to clipboard option on this forum does not seem to work with my laptop, I am using Google Chrome.

Workaround: Click "view plain" instead of "copy to clipboard", then select the text in the popup window and copy it with Ctrl+C.



lol, how could I forget to create a method() that Java actually looks into for executing code, btw is '...' considered valid for passing arguments?


Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14153
    
  18

The "..." is called varargs, one of the new features of Java 5.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: array[] [] ?