• 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

array[] [] ?

 
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See anything wrong here?



Output: Tool completed with exit code 2
 
Jon Camilleri
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your line:

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

Is an incomplete declaration/creation of the array. Why?
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And:is incorrect - the bit in < > must be a type, not a variable.
 
Jon Camilleri
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 563
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jon Camilleri
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "..." is called varargs, one of the new features of Java 5.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic