返回列表 發帖

302-巢狀迴圈

import java.util.Scanner;
public class JPA03 {
    public static void main(String[] args) {
        int i = 1, j = 1, count = 0;
        for (i = 1; i <= 3; i++) {        //第一個迴圈,i從1到3
            ...
            }
        }
        System.out.printf("count = %d\n", count);
    }
}
Stay hungry,
Stay foolish.

  1. package text;
  2. import java.util.Scanner;
  3. public class JPA03 {
  4.     public static void main(String[] args) {
  5.         int i = 1, j = 1,k=1, count = 0;
  6.         for (i = 1; i <= 3; i++)
  7.         {        //第一個迴圈,i從1到3
  8.           for (j=1;j<=2;j++)
  9.           {
  10.                   for (k=1;k<=9;k++)
  11.               {
  12.                       count++;
  13.               }
  14.           }
  15.         }
  16.         System.out.printf("count = %d\n", count);
  17.     }
  18. }
複製代碼

TOP

package ffddasfdfas;

public class dasfafd {

        public static void main(String[] args) {
                // TODO 自動產生的方法 Stub
                  int i = 1, j = 1, count = 0;
                for (i = 1; i <= 3; i++) {        //第一個迴圈,i從1到3
                  for(j=1;j<=3;j++)
                  {
                          for(int k=1;k<=6;k++)
                          {
                                  count++;
                          }
                  }
                  
                    }  System.out.printf("count = %d\n", count);
                }
             
        }

TOP

  1. public class hi87 {

  2.         public static void main(String[] args) {
  3.                 // TODO 自動產生的方法 Stub
  4.                 int count=0;
  5.                 for(int i=1;i<=3;i++)
  6.                 {
  7.                         for(int j=1;j<=3;j++)
  8.                         {
  9.                                 for(int z=1;z<=6;z++)
  10.                                 {
  11.                                         count++;
  12.                                 }
  13.                         }       
  14.                 }
  15.                 System.out.printf("count = %d\n",count);
  16.         }

  17. }
複製代碼

TOP

返回列表