//定義未來要用到的變數
public static int a = 1;
public static int b = 2;
public static int c = 3;
public static int d = 4;
public static int e = 5;
public static int f = 6;
public static int g = 7;
public static int h = 8;
public static int i = 9;
//程式進入點main
public static void main(String[] args){
//宣告一個所有回圈共用的變數y
int y = 0;
//在每個for迴圈裡獨立宣告各回圈專用的變數x
for (int x=1;x<10;x++){
y = x * a;
//用System.out.println指令輸出運算結果
System.out.println("1 x " + x + " = " + y);
}
for (int x=1;x<10;x++){
y = x * b;
System.out.println("2 x " + x + " = " + y);
}
for (int x=1;x<10;x++){
y = x * c;
System.out.println("3 x " + x + " = " + y);
}
for (int x=1;x<10;x++){
y = x * d;
System.out.println("4 x " + x + " = " + y);
}
for (int x=1;x<10;x++){
y = x * e;
System.out.println("5 x " + x + " = " + y);
}
for (int x=1;x<10;x++){
y = x * f;
System.out.println("6 x " + x + " = " + y);
}
for (int x=1;x<10;x++){
y = x * g;
System.out.println("7 x " + x + " = " + y);
}
for (int x=1;x<10;x++){
y = x * h;
System.out.println("8 x " + x + " = " + y);
}
for (int x=1;x<10;x++){
y = x * i;
System.out.println("9 x " + x + " = " + y);
}
}
}
程式跑出來的結果:
1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
.
.
.
1 x 8 = 8
1 x 9 = 9
2 x 1 = 2
2 x 2 = 4
.
.
.
以此類推直到9 x 9 = 81為止