• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem Initializing a 2D Array  RSS feed

 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac 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[][]);
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • 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:
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THis should work:

 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java 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[][]".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!