Results 1 to 8 of 8
Like Tree2Likes
  • 2 Post By nonybrighto

Thread: Array multiplication table

  1. #1
    nonybrighto is offline Member
    Join Date
    Oct 2012
    Location
    ph
    Posts
    43
    Rep Power
    0

    Default Array multiplication table

    Please guys help me out....i tried making a multiplication table using this code and all i get is an arrayindex out of bounds error....but i dont know what to do.....i searched d forum but didnt find any solution...please help...dis is the code..


    Java Code:
    public class array {
        public static void main(String[] args)
        {
            int[][] array=new int[11][11];
            
            int row;
            int col;
            for( row=1;row<=10;row++)
            {
                for(col=1;col<=10;col++)
                    array[row][col]=row*col;
                System.out.print(" " +array[row][col]);
            }
            System.out.println();   
        }
        
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Array multiplication table

    All code blocks including for loops, if blocks, while loops, etc should be enclosed within curly braces. Your lack of braces are what's causing your problem. I'll explain in a bit after test that this is in fact true.

    Awaiting your reply.

    Oh, and next we'll talk about arrays being 0-based.

  3. #3
    nonybrighto is offline Member
    Join Date
    Oct 2012
    Location
    ph
    Posts
    43
    Rep Power
    0

    Default Re: Array multiplication table

    Thanks a lot....i found out i didnt put the brace in the for loop and it works when i use array.length-1 but gives me out of bound when i used array.length.....is it because of the initialization to 1?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Array multiplication table

    Please show your latest code please plus the error message, plus an indication by comment in code which line is throwing the exception.

  5. #5
    nonybrighto is offline Member
    Join Date
    Oct 2012
    Location
    ph
    Posts
    43
    Rep Power
    0

    Default Re: Array multiplication table

    Dnt worry bro!!...i found d fault....i have solved it!!!......can u suggest any gud java book 4 me....apart 4rm Deitel deitel

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Array multiplication table

    Quote Originally Posted by nonybrighto View Post
    Dnt worry bro!!...i found d fault....i have solved it!!!......can u suggest any gud java book 4 me....apart 4rm Deitel deitel
    This is a programming forum, not SMS chat. Please use proper words.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Array multiplication table

    I agree with Darryl. Please remember that,

    • Programming is an exercise in precision. When you communicate here (or anywhere) about programming issues and questions, you want this communication to be as clear as possible to avoid any chance for ambiguity. I'd say at least half the answers here are requests for clarification. Let's avoid that.
    • For many here, English is not their first (or second or third) language. It's hard enough for them to understand what people are posting here much less if it's couched in obscure and non-standard abbreviations.
    • Extra letters don't cost anything here, so you might as well use them.

  8. #8
    nonybrighto is offline Member
    Join Date
    Oct 2012
    Location
    ph
    Posts
    43
    Rep Power
    0

    Default Re: Array multiplication table

    Quote Originally Posted by DarrylBurke View Post
    This is a programming forum, not SMS chat. Please use proper words.

    db
    ...ow!!!....my bad.....sorry about that.....i'm stilltrying to get used to posting here without short forms......i'm sorry..
    Fubarable and DarrylBurke like this.

Similar Threads

  1. Multiplication Table
    By BillyB in forum New To Java
    Replies: 17
    Last Post: 12-24-2010, 06:58 AM
  2. need help with this: multiplication table
    By MsIceCold in forum New To Java
    Replies: 7
    Last Post: 07-13-2010, 01:31 PM
  3. Multiplication Table
    By SwEeTAcTioN in forum New To Java
    Replies: 4
    Last Post: 02-24-2010, 04:11 AM
  4. Multiplication table
    By rjones215 in forum New To Java
    Replies: 3
    Last Post: 10-19-2009, 04:34 PM
  5. Help with multiplication table
    By Albert in forum New To Java
    Replies: 1
    Last Post: 07-10-2007, 04:44 PM

Posting Permissions

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