This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Problem Initializing a 2D Array

 
Ranch Hand
Posts: 176
Mac Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Note: This isn't the whole program. function HAMMING(int[][]) isn't displayed.

Isn't this how we defined and initialize 2D arrays ? The errors I get are:

(x8, for each line: int a[...][] = [...])
illegal start of expression
] accepted
not a statement

then...

incompatible tpyes @static int[][] a = new Integer[8][8];
cannot resolve class a
unexpected types @par = exe.HAMMING(a[][]);
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

a[0][]= [0,1,0,1,0,1,0,1];
a[1][]= [1,1,1,1,0,0,0,0];
a[2][]= [1,1,0,0,0,0,0,0];


This is not the correct syntax in Java. Do it like this:
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THis should work:

 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

incompatible tpyes @static int[][] a = new Integer[8][8];
cannot resolve class a
unexpected types @par = exe.HAMMING(a[][]);


Although int and Integer can be mixed, int[] and Integer[] or int[][] and Integer[][] cannot. So turn it into "new int[8][8]". Next you need to pass the array as "a", not as "a[][]".
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic