0

値を3列3行で表示したいと思います。これは私のコードです:

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列です。

"x" の代わりに "\u00d7" または "×" を書くことができます。これは実際の数学演算子 × です。

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
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 に答える
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 に答える