0

我想在三列和三行中显示值。这是我的代码:

public class MultiplicationTable {

    public static void main(String[] args) {

        for(int i=2;i<=10;i++){
            System.out.println();
            System.out.println(" The table " + i);
          for(int j=2;j<=10;j++) {
              System.out.println(" " +i + " x " + j + " = " + i*j + "\t");
          }
       }
    }
}
4

3 回答 3

0

(更正)我太傻了;只是普通的表,但在 3 列中。

你可以写成“\u00d7”或“×”而不是“x”,这是真正的数学运算符×。

public static void main(String[] args) {
    final String TAB = "    ";
    for(int y = 0; y < 3; y++) {
        for(int j = 2; j <= 10; j++) {
            for (int x = 0; x < 3; x++) {
                int i = 2 + y*3 + x;
                System.out.printf("The table %2d  " + TAB, i);
                System.out.printf("%2d x %2d = %3d" + TAB, i, j, i*j);
            }
            System.out.println();
        }
        System.out.println();
    }
}
于 2013-02-25T00:25:09.610 回答
0
String temp     = "";
String lbl      = "TABLE #";

int num         = 10,
    rowLength   = 10,
    colLength   = 3;

int tableNumber = 1, 
    counter     = colLength,
    index       = 1;


for ( int colLabel = index; colLabel <=num; colLabel++, tableNumber++ ){                        
    System.out.printf("%11s %-10s",lbl + tableNumber, "");

    if ( colLabel == counter || colLabel == num ){
        System.out.println();
        for ( int row = 1; row <=rowLength; row++){
            for ( int column = index; column <=colLabel; column++){
                temp    = String.format("%4d x %-3d= ", column, row );
                temp   += String.format("%-10d",(column * row));
                System.out.printf("%20s",temp);
            }   
            System.out.println();
        //  temp = "";
        }

        System.out.println("\n");
        index    = (tableNumber + 1);                               
        counter += colLength;   
    }                               
}
于 2013-09-18T14:13:39.470 回答
0
for(int i=2;i<=10;i++){
    System.out.println();
    System.out.println(" The table " + i);
    for(int j=2;j<=10;j++) {
        System.out.println( i + " x " + j + " = " + i*j );
    }
}
于 2013-04-15T00:33:31.963 回答