I've to write code for:
I'd written the code:
public class tables {
public static void main(String[] args) {
//int[][] table = new int[12][12];
String table="";
for(int i=1; i<13; i++){
for(int j=1; j<13; j++){
//table[i-1][j-1] = i*j;
table+=(i*j)+" ";
}
System.out.println(table.trim());
table="";
}
}
}
But the problem is with the output format. I need the output in a matrix like fashion, each number formatted to a width of 4 (the numbers are right-aligned and strip out leading/trailing spaces on each line). I'd tried google but not find any good solution to my problem. Can anybody help me out?
See Question&Answers more detail:os