# JAVA程式問題

java程式 可以用 for loop指令 寫出99乘法表

1x1=1 1x2=2 1x3=3 (要有空格~~列一出來不會黏在一起)

2x1=2 2x2=4 2x3=6

Rating

Here is the code

public class Calculator {

public static void main(String[] args){

Calculator cal = new Calculator();

cal.draw();

}

public void draw(){

for(int i=1; i< 10 ;i++){

for(int j =1; j<10; j++){

System.out.print(i+" x "+j+" = "+ i*j+"\t");

}

System.out.println("");

}

}

}

The output is

1 x 1 = 11 x 2 = 21 x 3 = 31 x 4 = 41 x 5 = 51 x 6 = 61 x 7 = 71 x 8 = 81 x 9 = 9

2 x 1 = 22 x 2 = 42 x 3 = 62 x 4 = 82 x 5 = 102 x 6 = 122 x 7 = 142 x 8 = 162 x 9 = 18

3 x 1 = 33 x 2 = 63 x 3 = 93 x 4 = 123 x 5 = 153 x 6 = 183 x 7 = 213 x 8 = 243 x 9 = 27

4 x 1 = 44 x 2 = 84 x 3 = 124 x 4 = 164 x 5 = 204 x 6 = 244 x 7 = 284 x 8 = 324 x 9 = 36

5 x 1 = 55 x 2 = 105 x 3 = 155 x 4 = 205 x 5 = 255 x 6 = 305 x 7 = 355 x 8 = 405 x 9 = 45

6 x 1 = 66 x 2 = 126 x 3 = 186 x 4 = 246 x 5 = 306 x 6 = 366 x 7 = 426 x 8 = 486 x 9 = 54

7 x 1 = 77 x 2 = 147 x 3 = 217 x 4 = 287 x 5 = 357 x 6 = 427 x 7 = 497 x 8 = 567 x 9 = 63

8 x 1 = 88 x 2 = 168 x 3 = 248 x 4 = 328 x 5 = 408 x 6 = 488 x 7 = 568 x 8 = 648 x 9 = 72

9 x 1 = 99 x 2 = 189 x 3 = 279 x 4 = 369 x 5 = 459 x 6 = 549 x 7 = 639 x 8 = 729 x 9 = 81

2007-11-01 11:08:34 補充：

事實上 /t 會有 space between 1X1=1 and 1X2 =2

這個 past 上去秀出不來

Source(s): 我寫的
• 幽靈
Lv 5

public class Java1

{

public static void main(String[] args)

{

for (int i = 1; i <= 9; i++)

{

for (int j = 1; j <= 9; j++)

{

System.out.print(i + "x" + j + "=");

System.out.print(i * j < 10 ? " " : "");

System.out.print((i * j) + " ");

}

System.out.println();

}

}

}