Solution to Array Problem

Content Author: myraid
Author website: http://www.geocities.com/myraid_77

import java.util.*;
public class Test {
    public Test() {
    }

    public int[][] rearrangeArray( int[][] args ) throws Exception {
        if( args == null ) {
            return null ;
        }
        if( args.length == 0 ) {
            int[][] out = {} ;
            return out ;
        }
        int r = args.length ;
        int c = args[0].length ;
        int[][] out = new int[r][c] ;
        for( int i=0; i<c; i++ ) {
            int[] col = new int[r];
            for( int j=0; j<r; j++ ) {
                col[j] = args[j][i] ;
            }
            sort( col );
             for( int j=0; j<r; j++ ) {
                out[j][i] = col[j];
            }
        }
         return out ;
    }

    public void sort( int[] in ) {
        Arrays.sort( in );
    }

    public static void main( String[] args ) throws Exception {
        int[][] in = { { 0, 0 , -1 } , { 5 , -6 , 7 } ,{ 0, 0 , 8 } , { 
-6 ,2 , 3 }, { 4, 0 , 1 } , { 1 ,2 , 3 } } ;
        Test test = new Test();
        int[][] out = test.rearrangeArray( in ) ;
    }
}

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.