Monday, December 29, 2014

Error ']' excpected in 2D Array Java Program




I am trying this code .But everytime it is giving me this error on compiling



Printdiagonal.java:21: error: ']' expected



System.out.println(a[j,temp]);



^



Printdiagonal.java:21: error: ')' expected



System.out.println(a[j,temp]);



^



Printdiagonal.java:21: error: illegal start of expression



System.out.println(a[j,temp]);






Java Code:






class Printdiagonal
{

public static void main(String...s)
{
Printdiagonal P=new Printdiagonal();
P.print(new int[][] {{1,567,4,3,33},{0,333,677,34243,8987,3434,324},{446,876,23,546565,332}});
}

void print(int [][]a)

{
for(int i=0;i<a.length;i++)
{int temp=0;

temp=i;
while(temp>=0)
{
for(int j=0;j<=i;j++)
{
System.out.println(a[j,temp]);
temp--;
}
}
}
}


}







No comments:

Post a Comment