• 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

why is this array code creating error

 
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class demov
{
public static void main(String args[])
{
int a[][]=new int[][100];
}
}


what strange error is this??
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vishal Hegde wrote:class demov
{
public static void main(String args[])
{
int a[][]=new int[][100];
}
}


what strange error is this??



The error I got was:

Cannot specify an array dimension after an empty dimension

Pretty straight forward, actually. You basically can't say int a[][] = new int[][100], because you can't specifiy the [100] dimension without specificying the dimension of the bracket right before it. Some like int a[][] = new int[3][100] would work.
 
Vishal Hegde
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class demov
{
public static void main(String args[])
{
int a[][]=new int[100][];
}
}


then how is it runnning successfuly
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vishal Hegde wrote:class demov
{
public static void main(String args[])
{
int a[][]=new int[100][];
}
}


then how is it runnning successfuly



Because you have delcared the dimensions on the first bracket. You can do the first dimension, both dimensions, or neither. If it were a 3D array such as inta[][][]=new int[][][] you could put something in the first bracket, first and second bracket, or all three brackets, or none.
 
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to complete the chapter on Arrays that you are reading; believe me a few pages later you would get the answer of your question.
You will also learn or realize the fact that:
1. two dimensional arrays are actually arrays of objects
2. how you can simulate sparse matrices in Java

For your reading:
Arrays
2D Arrays

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic