Results 1 to 5 of 5
  1. #1
    masaka is offline Member
    Join Date
    Mar 2008
    Posts
    31
    Rep Power
    0

    Default How to reverse two dimensional

    if i have a two dimensional array and want to make another arraythat is the reverse of the first array how to do this

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    public class Test {
        public static void main(String[] args) {
            int[][] forward = {
                { 1, 2, 3, 4 },
                { 5, 6, 7, 8 }
            };
            int rows = forward.length;
            int cols = forward[0].length;
            int[][] reverse = new int[rows][cols];
            for(int i = rows-1; i >= 0; i--) {
                for(int j = cols-1; j >= 0; j--) {
                    reverse[rows-1-i][cols-1-j] = forward[i][j];
                }
            }
            for(int i = 0; i < rows; i++) {
                for(int j = 0; j < cols; j++) {
                    System.out.print(reverse[i][j]);
                    if(j < cols-1)
                        System.out.print(", ");
                }
                System.out.println();
            }
        }
    }

  3. #3
    masaka is offline Member
    Join Date
    Mar 2008
    Posts
    31
    Rep Power
    0

    Default

    thanks but how to make the colums rows and the rows colums without reversing

  4. #4
    asheesh_arora is offline Member
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Default

    Hi You can find the code at:

    forum4everyone.com - How to transpose an array

  5. #5
    masaka is offline Member
    Join Date
    Mar 2008
    Posts
    31
    Rep Power
    0

    Default

    thanks alot for you
    I love this site very much because there are many guys help me thanks to all of you
    Last edited by masaka; 05-19-2008 at 11:12 AM.

Similar Threads

  1. How to initialize a two dimensional Array
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 09:48 PM
  2. Replies: 1
    Last Post: 03-26-2008, 12:41 PM
  3. 2 dimensional Lists
    By gapper in forum New To Java
    Replies: 4
    Last Post: 01-20-2008, 10:01 AM
  4. Help with array multi-dimensional
    By barney in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 09:00 PM
  5. Reverse engineer a java code
    By lenny in forum Advanced Java
    Replies: 1
    Last Post: 07-26-2007, 12:14 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
  •