This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

why is this array code creating error

 
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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

 
In the renaissance, how big were the dinosaurs? Did you have tiny ads?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic