Results 1 to 6 of 6
  1. #1
    Insaeno is offline Member
    Join Date
    Aug 2008
    Posts
    2
    Rep Power
    0

    Default Question - I'm a noob!

    Please reply to this as soon as possible, please.

    My method is as follows:
    public void main (int a[][])
    But when I enter the input as {1,2,3 .......} it shows:
    Error: incompatible types - found int but expected int []

    What does this mean?

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    In the method you need two dimensional array. But your arguments are just an int values. That's why compiler complain it.

  3. #3
    Insaeno is offline Member
    Join Date
    Aug 2008
    Posts
    2
    Rep Power
    0

    Default

    I'm sorry I didn't get you. Isn't that how you enter data for a two dimensional array as well, within curly brackets?

    (PS: I apologize at my ignorance, this is my first attempt with Arrays)

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    No, defining a 2D array is as follows.

    Java Code:
    int temp[][] = new int[3][3];
    Basically what we called is that 2D array is an array of arrays. That's mean each array element holds another array.

    like this,

    Java Code:
    temp[0] = {1, 2, 3};
    temp[1] = {10, 20, 30};
    temp[2] = {100, 200, 300};
    Is that clear?

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Or do it all in the declare/define statement:
    int[][] twoDim = new int[][] {{1, 3}, {3, 5,7}};

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Noob
    By nokomis in forum Introductions
    Replies: 2
    Last Post: 03-06-2009, 06:10 PM
  2. Please help a noob :)
    By Bays in forum New To Java
    Replies: 15
    Last Post: 06-17-2008, 07:11 AM
  3. Noob question- easy
    By mattonitto in forum New To Java
    Replies: 7
    Last Post: 06-13-2008, 01:26 AM
  4. [noob]Problem with TOS .bat
    By fred33 in forum Advanced Java
    Replies: 0
    Last Post: 03-19-2008, 03:04 PM
  5. Ah! Help a Java Noob
    By Snejana in forum New To Java
    Replies: 4
    Last Post: 01-24-2008, 04:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •