/* * Created on Jul 27, 2004 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** * @author Administrator * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class Exercise2 { public static void main(String[] args) { final int maxRow = 12; final int maxCol = 12; String pad = " "; int[][] table= new int[maxRow][maxCol]; for (int i = 0; i < maxRow; i++) { for (int j = 0; j < maxCol; j++) { table[i][j] = (i+1)*(j+1); } } System.out.print(" | "); for (int i = 1; i <= maxRow; i++) { System.out.print(format(i)); } System.out.println(); System.out.print("--------+-"); for (int i = 0; i < maxRow; i++) { System.out.print("----------"); } System.out.println(); for (int i = 0; i < maxRow; i++) { System.out.print(format(i+1) + " | "); for (int j = 0; j < maxCol; j++) { System.out.print(format(table[i][j])); } System.out.println(); } } public static String format(int val) { String pad = " "; String newVal = pad + val; return newVal.substring(newVal.length() - pad.length()); } }