LoginSignup
1
1

More than 3 years have passed since last update.

Java SE Bronze 試験番号: 1Z0-818 (ループ文 編)(2020年10月)

Last updated at Posted at 2020-10-27

公式サイト: Java SE Bronze

oracle.PNG

目的

:cherry_blossom: Java Bronze SE 合格 :cherry_blossom:

目次

1, while文の使用
2, for文および拡張for文の使用
3, do-while文の作成と使用
4, ループのネスティング

oracle java.PNG
公式サイト: The Java™ Tutorials

1, while文の使用

while文 while(条件):条件がtrueである限り、無限ループします。

WhileDemo.java
class WhileDemo {
    public static void main(String[] args) {        
        int count = -10;
        while(count < 1) {
            System.out.println("Count is : " + count);
            count++;
        }
    }
}

2, for文および拡張for文の使用

for文

ForDemo.java
class ForDemo {
    public static void main(String[] args) {        
        for(int i = 0; i < 11; i++) {
        System.out.println("Count is : " + i);
    }
}

拡張for文

EnhancedForDemo.java
class EnhancedForDemo {
    public static void main(String[] args) {

        int[] numbers = {1,2,3,4,5,6,7,8,9,10};
        for(int item : numbers) {
            System.out.println("Count is : " + item);
        }
    }
}

3, do-while文の作成と使用

do-while文 条件に関わらず、一度は表示する。

DoWhileDemo.java
class DoWhileDemo {
    public static void main(String[] args) {        
        int count = 1;
        do {
            System.out.println("Count is : " + count);
            count++;
        }while(count < 11); 
    }
}

4, ループのネスティング

ネスティング for文の中にfor文を記述。下記のソースコードは九九を表しています。

Nesting.java
class NestingDemo {
    public static void main(String[] args) {        
        for(int i = 1; i < 10; i++) {
            for(int j = 1; j < 10; j++) {
                System.out.print((i * j) + ",");    
            }
            System.out.println(""); 
    }
}

備考

1, データの宣言と使用 編
2, ループ文 編

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1