用兩次for循環打贏出九九乘法表,相信很多人都知道,這次我們要用一次循環去幹這事,其實也挺簡單的,看代碼吧
/**
* 只用一次循環打印出99乘法表
*
* @author Administrator
*
*/
public class OnceCircle {
public static void main(String[] args) {
// 由於只能用一次循環,且不知道次數所以用while去實現
int i = 1;
int j = 1;
while (true) {
// 程序出口
if (i > 9) {
break;
}
System.out.print(i + "*" + j + "=" + i * j + " ");
if (j < i) {
j++;
} else {
j = 1;
i++;
System.out.println();
continue;
}
}
}
}
結語:Knowing yourself is the height of wisdom!