0
class TwoDimArryAlloc {
  public static void main(String[] args) {
       int itemno[][] = new int[][] {  {2234,2235,2236,2237,2238}  ,   {3334,3335,3336,3337,3338}  };
       int it;

       String itemdesc[][] = new String[][] {{"Womans Item1","Womans Item2","Womans Item3","Womans Item4","Womans Item5"},{"Mans  Item1","Mans Item2","Mans Item3","Mans Item4","Mans Item5"}};


       for (int i=0; i<2; i++)
       {
           for(int j=0; j<5; j++)
           {
               System.out.println(itemno[][]);
           }
       }
  }
}

In the above program, I got the following error:

C:\Java Programs\TwoDimArryAlloc.java:18: '.class' expected
                System.out.println(itemno[][]);
                                             ^
1 error

Process completed.

Can anyone help me solve this error?

1
  • And please format your code correctly... Commented Aug 23, 2011 at 11:54

5 Answers 5

1

You need to provide the array index:

System.out.println(itemno[i][j]);
                          ^  ^
Sign up to request clarification or add additional context in comments.

Comments

1

Instead of

System.out.println(itemno[][]);

you want to say

System.out.println(itemno[i][j]);

Without specifying which indexes you want, it is bad syntax, which confuses the compiler so much that it emits an impenetrable error message.

(The first pass of compilation is to construct a syntax tree, and this happens before the compiler figures out which names denote types and which ones denote variables. So when it sees itemno[][] it reasons that this could be the beginning of a valid expression if only itemno were the name of a type, but in that case the full expression would have to be itemno[][].class -- so that's what it asks for even though you meant something entirely different).

Comments

1
{
    int itemno[][] = { {2234,2235,2236,2237,2238}  ,   {3334,3335,3336,3337,3338}  };
    int it;

    String itemdesc[][] = {{"Womans Item1","Womans Item2","Womans Item3","Womans Item4","Womans Item5"},{"Mans  Item1","Mans Item2","Mans Item3","Mans Item4","Mans Item5"}};


    for (int i=0; i<2; i++)
    {
        for(int j=0; j<5; j++)
        {
            System.out.println(""+itemno[i][j]); 
        }




    }
}

Comments

0

You forgot to provide index in SYSO statement. Make it as follow:

System.out.println(itemno[i][j]);

Comments

0

You forgot to use the indexes:

System.out.println(itemno[i][j]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.