Write out what style you want to implement in an excel spreadsheet and count the number of rows and columns.
There should be 10 columns. The row number takes up one column. Don't you consider that the row number takes up one column?
99 Multiplication table, second row data cannot be aligned
public static void main(String[] args) {
for(int i=1;i<10;i++){
System.out.print(i+"\t");
if(i==1){
for(int j=1;j<10;j++){
System.out.print(j+"\t");
}
System.out.println("");
}
for(int j=1;j<10;j++){
System.out.print(i+"X"+j+"="+i*j+"\t");
}
System.out.println("");
}
}
0 Answer
Write out what style you want to implement in an excel spreadsheet and count the number of rows and columns.
There should be 10 columns. The row number takes up one column. Don't you consider that the row number takes up one column?
two layers of loop, the outer control row, the inner control column, and then the column is not aligned, that is the problem of the inner loop, the inner loop is 9 times, so 9 columns is no problem, you can add a judgment before the inner loop, When it's row 1, column 1 print a tab key
if(i==1&&j==1){
System.out.print("\t");
}
这家伙很懒,什么都没留下...