Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Two dimensional Arrays

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    8
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Two dimensional Arrays

    I've posted this on another part of this forum as well but more people are viewing in here.

    I know most about them but the one thing I can't work out is, how do you put one Arrays values into another?

    Something about nested for loops? Not sure how to do them though...?

    I basically need to do this:

    Write a public instance method called writeLetter() which takes a single argument
    of type char called aCharacter and returns no result. The method should first invoke
    the getLetter() method on the LEDFont class with aCharacter as its argument. As
    stated earlier, getLetter() returns a two-dimensional array of type boolean which
    has has CONSTANT_ONE rows and CONSTANT_TWO columns,
    representing the LED settings for aCharacter. The array should be assigned to an
    appropriately declared local variable called letter. The method should then copy the
    boolean values from letter into matrix starting at the first row and column,
    overwriting existing values.

    >>>Little back ground about this,

    LEDFont is purely just used for its "getLetter" method, so I need to invoke that method and it will then return a two dimensional boolean Array.

    matrix is a 2D boolean Array which outputs a display, its values make up 5 rows and 60 columns so at this stage them elements are false and are represented by a '.' but if any elements are true then that true element will be represented by a 'O' .

    So basically the 2D boolean Array that is returned (letter), its values and elements need to go into 'matrix' so that it can output what ever the user entered for aCharacter.

    I hope all this makes sense!
    Last edited by masterT; July 18th, 2011 at 06:28 PM. Reason: Removed the cool glasses smiley as it offended dlorde.... sorry :-\


  2. #2
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Two dimensional Arrays

    Quote Originally Posted by masterT View Post
    I've posted this on another part of this forum as well but more people are viewing in here
    I think you'll find that multiple posting is not considered cool.

    If you want help with nested loops, just ask.
    Last edited by dlorde; July 18th, 2011 at 06:27 PM.

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    8
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Two dimensional Arrays

    I have removed the ........................................
    Should I remove one of the threads as well if its offending you?

  4. #4
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Two dimensional Arrays

    Quote Originally Posted by masterT View Post
    Should I remove one of the threads as well if its offending you?
    It doesn't offend me, it's just thoughtless. The mods will probably remove it.

  5. #5
    Junior Member
    Join Date
    Jul 2011
    Posts
    8
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Two dimensional Arrays

    Hi dlorde, please forgive me.... Im going a little crazy and I just need help (famous last words!) I'm kinda in a thoughtless mood to be honest and would appreciate any help that you could give me. I know when you see things like this, you probably just want to move onto the next thread but please help. If a mod can remove the other one then ok then but for now if an expert like you can help then please do

  6. #6
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Two dimensional Arrays

    So what are you asking, exactly? The more specific the question, the more specific the answer is likely to be.

    If you want help with nested loops, just ask.

  7. #7
    Junior Member
    Join Date
    Jul 2011
    Posts
    8
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Two dimensional Arrays

    Ok, so how can I put values from one 2D array into another using a nested loop?

  8. #8
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Two dimensional Arrays

    If you think of the array in terms of multiple rows, with multiple items in each row (i.e. rows & columns). You write a loop that iterates over the rows, using a row counter, so it deals with one row (array of items) each time round; then inside that loop, you write another loop that takes the current row and iterates over it using a column counter, to access each column (item) in the row. So for each item, you'll have the row index and the column index, so you can copy that item from the 2D source array to the 2D destination array:

    destinationArray[rowIndex][columnIndex] = sourceArray[rowIndex][columnIndex];

    Don't forget that array indexes start at zero, and be sure that the destination array has been initialized to the correct size.

  9. #9
    Junior Member
    Join Date
    Jul 2011
    Posts
    8
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Two dimensional Arrays

    Hi dlorde, I noticed you commented on an exact same problem thread > http://www.javaprogrammingforums.com...n-array-5.html <
    So in this case you also mention about a single loop? How can this be done? Do you have any examples? With the 2D boolean array that is mentioned "letter" we dont actually get the elements value, its just returned by LEDFont so that we can use it to over ride matrix...

    Sounds pretty stupid, but hey thats our great assignment!

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Two dimensional Arrays

    about a single loop? How can this be done?
    The single loop copied a full row at each time around the loop.
    A two dim array is made up of a bunch of one dim arrays. For example:
    <type>[][] twoDim = new <type>[10][5];
    Then
    twoDim[0] is a one dim array of <type>[5]
    the same for the other indexes from 1 to 9. A total of 10 one dim arrays with 5 elements each.

  11. #11
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Two dimensional Arrays

    Thanks Norm

Similar Threads

  1. Two-dimensional boolean array?
    By tcmei in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 17th, 2011, 08:32 PM
  2. help w/ storing/scanning numbers in two dimensional arrays
    By robertsbd in forum What's Wrong With My Code?
    Replies: 10
    Last Post: December 1st, 2010, 11:56 PM
  3. Two dimensional arrays - HELP!
    By ecco in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 19th, 2010, 12:32 PM
  4. How to show 2D array using combobox and radiobutton?
    By Broken in forum Loops & Control Statements
    Replies: 1
    Last Post: March 10th, 2009, 06:01 AM