打印九九乘法表,及倒打印,
class Print99 {
public static void main(String[] args) {
for (int i = 1;i <= 9 ;i++ ) {
for (int j = 1; j <= i ;j++ ) {
int a = i * j;
System.out.print(j+"*"+i+"="+a+"\t");
}
System.out.println();
}
System.out.println("----------------------------------");
for (int i = 9;i >= 1 ;i-- ) {
for (int j = 1; j <= i ;j++ ) {
int a = i * j;
System.out.print(j+"*"+i+"="+a+"\t");
}
System.out.println();
}
}
}
倒打印规律总结:
只需把外循环中初始化表达式,条件表达式,循环后表达式全部反向取值即可。
即:for (int i = 1;i <= 9 ;i++ ) 修改成for (int i = 9;i >= 1 ;i-- ) 即可实现反转;
|
|