小破站自学java———黑马java视频
学到嵌套循环的时候,遇到了本次的一切的源头(万恶之源)
一个弹幕———“可以尝试用嵌套循环写九九乘法表了”
于是乎,我逐渐变成,就这样子的表情。
在想到九九乘法表的第一课,我想到的是 for循环的嵌套循环,这是我来自于小白的思路。
public class test99biao {
public static void main(String[] args) {
for (int j = 0; j < 10; j++) {
//lie
// System.out.print(j+"t");
for (int i = 0; i < 10; i++) {
//hang
int product = i * j;//定义一个乘积
if (product != 0) {
System.out.print(product + "t" );
}
}
System.out.println();//换行
System.out.println();
}
}
}
到目前为止,我感觉我的思路和操作都是正确的,因为他能出结果藍
室友的补刀——既然for嵌套可以,那while是不是也可以在听到这个的第一刻,本着小白的身份,我进行了反驳,“while是不知道次数才用的循环”但好像也不是不可以用,于是我开始我的迷途了。
一开始是想着对着已经写出来的for循环进行套用,于是就有了
public class test99biao {
public static void main(String[] args) {
int h = 1;//行
int l = 1;//列
while (h < 10) {
l=1;
while ( l <=h){
int sum = h * l;
System.out.print( sum+ "t");
l++;
}
h++;
System.out.println();
}
}
}
只有上面for循环九九乘法表的一半!!!
让我百思不得其解!!
拜访csdn大佬后———原来从一开始思路就有点问题!!正解!!!原来一开始想法就是错的!!但是也走出了自己的道路,java从入门到入坟!



