0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

java 繰り返し処理

Posted at

今日はjavaの繰り返し処理について書きます。

繰り返し文とは

一定の指示を与えた命令を繰り返す処理のこと

実行結果をこう出す場合

[1]
[2]
[3]
[4]
[5]

通常だと

通常処理
 public class PrintFiveStars { |
      public static void main (String[] args){ |
          System.out.println("[1]"); 
          System.out.println("[2]"); 
          System.out.println("[3]"); 
          System.out.println("[4]"); 
          System.out.println("[5]"); 
      } 
 } 

繰り返し構文を使用した場合
5行ほどで済みます。
これを応用すれば、100でも1000行でも
編集するだけで処理を行うことができます。

繰り返し処理

public class Print100Stars {
    public static void main (String[] args) {
     int sum = 0;
     for (int i = 1; i <= 5; i++){
          sum += 1;
          System.out.println(sum);
      }
  }
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?