Thursday, January 20, 2011

Finding transpose of mXm matrix using JAVA

public class MultiArray {
       public static void main(String[] args) {
             // Declare and construct the M X M matrix.
             int[][] mXmArray = { { 16, 7, 12, 8 }, { 9, 20, 18, 2 },{ 14, 11, 5, 1 }, { 8, 5, 10, 0 } };
            
             for (int i = 0; i < mXmArray.length; ++i) {
                          int[] verify = mXmArray[i];
                          if (verify.length != mXmArray.length) {
                                throw new IllegalArgumentException("The matrix suppliing shuld be a square matrix");
                         }
             }
             // Interchanging non diagonal array elements.
             for (int i = 0; i < mXmArray.length; i++) {
                   for (int j = 0; j < mXmArray[i].length; j++) {
                        if (j != i && j > i) {
                               mXmArray[i][j] = mXmArray[i][j] + mXmArray[j][i];
                               mXmArray[j][i] = mXmArray[i][j] - mXmArray[j][i];
                               mXmArray[i][j] = mXmArray[i][j] - mXmArray[j][i];
                       }
                  }
           }
          // Priniting back the changed elements.
         for (int i = 0; i < mXmArray.length; i++) {
               for (int j = 0; j < mXmArray[i].length; j++) {
                      System.out.println(i + " ::: " + j + " ::: " + mXmArray[i][j]);
               }
        }
   }

}

Sunday, July 25, 2010

removing duplicates from an array

With the following java program we can view the array after removing the duplicate elements from an array

public class RemoveDups {
     public static void main(String[] args) {
                int[] dups = new int[] { 0, 0, 0, 0 ,1, 2,2,3,4,5,6,7,2,3,4,5,6};
               removeDups(dups);
   }
   private static void removeDups(int[] dups) {
              int i, j;
              /* new length of modified array */
              int newLength = 1;
             for (i = 1; i < dups.length; i++) {
                   for (j = 0; j < newLength; j++) {
                         if (dups[i] == dups[j])
                              break;
                   }
                   if (j == newLength) {
                       dups[newLength++] = dups[i];
                  }
           }
           for (int y = 0; y < newLength; y++) {
                 System.out.println(dups[y]);
          }
     }
}

Sunday, June 20, 2010

count and ora:countNodes functions

Instead of count function use ora:countNodes with latest version of SOA suite.

Sunday, June 13, 2010

Thursday, June 3, 2010

Cron jobs in linux

Post @ http://www.scrounge.org/linux/cron.html was discussing about the cron jobs very neatly.