Advertisement
cd62131

Table Manipulation

Dec 20th, 2013
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.86 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.SortedSet;
  3. import java.util.TreeSet;
  4.  
  5. public class Main {
  6.   public static void main(String[] args) {
  7.     double[][] c = { {1, 1, 2}, {3, 1, 3}, {1, 1, 1}, {4, 2, 1}};
  8.     System.out.println("Before:");
  9.     for (int i = 0; i < c.length; i++)
  10.       System.out.println(Arrays.toString(c[i]));
  11.     double[] max = new double[c[0].length];
  12.     for (int i = 0; i < c[0].length; i++) {
  13.       SortedSet<Double> element = new TreeSet<Double>();
  14.       for (int j = 0; j < c.length; j++) {
  15.         element.add(c[j][i]);
  16.       }
  17.       max[i] = element.last();
  18.     }
  19.     for (int i = 0; i < c.length; i++) {
  20.       for (int j = 0; j < c[0].length; j++) {
  21.         c[i][j] /= max[j];
  22.       }
  23.     }
  24.     System.out.println("After:");
  25.     for (int i = 0; i < c.length; i++)
  26.       System.out.println(Arrays.toString(c[i]));
  27.   }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement