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

    Default How to transpose a 2D array

    From

    1,2.3,4
    5,6,7,8
    9,10,11,12
    13,14,15,16

    To

    1 5 9 13
    2 6 10 14
    3 7 11 15
    4 8 12 16

    Is it more easy to use 1D array than 2D array to transpose?
    I know that i use for loop as below it will display every row from 0 to 3,
    but how to put in the expression in the for loop so that i can apply the logic inside?

    for(int a = 0; a < 4; a++)
    {
    for(int b = 0; b < 4; b++)
    {
    group [a][b] = a + b +1;

    }
    }

    I know that to dislay the result below i must

    Logic
    1,2.3,4 (a+b+1)
    5,6,7,8 (a+b+4)
    9,10,11,12 (a+b+7)
    13,14,15,16 (a+b+10)

    Do i need to use any class?
    Last edited by kian_hong2000; 08-27-2008 at 06:43 AM.

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

    Default

    Yes, this is the "2D" forum, but here 2D stands for 2-dimensional graphics, usually problems involving the Graphics2D class. Your question should have been posted in the beginner's forum.

    That said, to solve your problem, why not create a second array, a pair of nested for loops, and copy items from one array at a time? You should try to work out the details on your own (by trying and failing and then ultimately succeeding, you'll learn more than by our just giving you the answer). Good luck!

Similar Threads

  1. Array help please
    By buzzdsm in forum New To Java
    Replies: 3
    Last Post: 06-19-2008, 12:43 AM
  2. Array Reflection: Multi Array Reflection
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 09:08 PM
  3. can anyone help... 2d Array
    By Mark1989 in forum New To Java
    Replies: 2
    Last Post: 03-12-2008, 09:59 PM
  4. Would appreciate your help with 2d Array..
    By cloudkicker in forum New To Java
    Replies: 1
    Last Post: 02-11-2008, 03:34 PM
  5. Help with Array
    By susan in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:32 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
  •