雙重循環的使用
- 外層循環變量變量變化一次,內層循環變化一遍
- 找規律很重要,固定寫法可以記憶,代碼理解
- 需先確定外層循環,內層循環
- 一定多敲兩遍,舉一反三
使用雙重循環輸出九九乘法表
☞實現方式:
兩層for嵌套,外層for輸出第一個乘數,內層for輸出第二個乘數,
循環條件為內層的數字小於等於外層的循環數字
1 /** 2 * 3 * 功能描述: 使用雙重循環輸出九九乘法表 4 * 5 * 6 * @Author: apple. 7 * @Date: 2019/11/23 1:49 PM 8 */ 9 public class Demo06 { 10 public static void main(String[] args) { 11 //乘數(a)--外 被乘數(b)--內 12 for (int a = 1; a <=9 ; a++) { 13 for (int b = 1; b <=a; b++) { 14 System.out.print(a+"*"+b+"="+(a*b)+"\t"); 15 } 16 System.out.println(); 17 } 18 } 19 }