Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-18-2008, 07:54 PM
Member
 
Join Date: Mar 2008
Posts: 31
Rep Power: 0
masaka is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 05-19-2008, 03:06 AM
hardwired's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
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();
        }
    }
}
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-19-2008, 05:05 AM
Member
 
Join Date: Mar 2008
Posts: 31
Rep Power: 0
masaka is on a distinguished road
Default
thanks but how to make the colums rows and the rows colums without reversing
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-19-2008, 06:47 AM
Member
 
Join Date: May 2008
Posts: 2
Rep Power: 0
asheesh_arora is on a distinguished road
Default
Hi You can find the code at:

forum4everyone.com - How to transpose an array
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-19-2008, 11:02 AM
Member
 
Join Date: Mar 2008
Posts: 31
Rep Power: 0
masaka is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to initialize a two dimensional Array Java Tip java.lang 0 04-14-2008 09:48 PM
Data Modeler plug-in with Reverse Engineering feature? vpin3515 Eclipse 1 03-26-2008 12:41 PM
2 dimensional Lists gapper New To Java 4 01-20-2008 10:01 AM
Help with array multi-dimensional barney New To Java 1 07-31-2007 09:00 PM
Reverse engineer a java code lenny Advanced Java 1 07-26-2007 12:14 AM


All times are GMT +2. The time now is 05:03 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org