表格应该是这样的:
我的表产生正确的输出。只需要对齐水平侧的值。
import java.util.Scanner;
公共课
{公共静态无效主要(字符串[]参数)
{
Scanner keyboard = new Scanner (System.in);
int rows=0, cols=0;
int a, b;
System.out.print("Enter number of rows from 1-10");
rows = keyboard.nextInt();
System.out.print("Enter number of columns from 1-10");
cols = keyboard.nextInt();
for (int c=1; c<=cols; c++){
System.out.print(" "+c);
}
System.out.println();
System.out.println( "----------------------");
for (int d=1; d<=rows;d++){
System.out.print(""+d);
System.out.println();
}
for ( a=1; a<=rows; a++)
{
for ( b=1; b<=cols; b++)
{
System.out.print(" "+a*b);
}
System.out.println();
}
}
}