public class PasswordXGrid {
public static void main(String args[]) {
new PasswordXGrid();
}
public PasswordXGrid() {
String[] h = { "1", "4" };
String[] v = { "32" };
System.out.println(minSum(h, v));
}
public int minSum(String[] horizontal, String[] vertical) {
int[][] array = new int[horizontal.length][vertical.length];
array[0][0] = 0;
int i, j = 0;
for (i = 0; i < array.length; i++) {
for (j = 0; j < array[i].length; j++) {
if (i == 0 && j == 0)
array[i][j] = 0;
else if (i == 0)
array[i][j] = array[i][j - 1]
+ Integer.parseInt(horizontal[i]
.substring(j - 1, j));
else if (j == 0)
array[i][j] = array[i - 1][j]
+ Integer.parseInt(vertical[i - 1].substring(j,
j + 1));
else
array[i][j] = getMax(
array[i][j - 1]
+ Integer.parseInt(horizontal[i].substring(
j - 1, j)),
array[i - 1][j]
+ Integer.parseInt(vertical[i - 1]
.substring(j, j + 1)));
}
}
System.out.println(i+" "+j);
System.out.println();
for (int ii = 0; ii < i; ii++) {
for (int jj = 0; jj < j; jj++) {
System.out.print(array[ii][jj] + " ");
}
System.out.println();
}
return array[i - 1][j - 1];
}
private int getMax(int i, int j) {
// TODO Auto-generated method stub
if (i > j)
return i;
else
return j;
}
}