0
0

Javaで「StringBuilderオブジェクトを初期化する」の動作を確認してみた

Posted at

概要

Javaで「StringBuilderオブジェクトを初期化する」の動作を確認してみました。以下のページを参考にしました。

実装

以下のファイルを作成しました。

JSample10_3.java
class JSample10_3{
  public static void main(String[] args){
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < 5; i++){
      for (int j = 0; j < 5; j++){
        sb.append((int)Math.ceil(Math.random() * 9));
      }

      System.out.println(sb.toString());
      sb.delete(0, sb.length());
    }
  }
}

以下のコマンドを実行しました。

$ javac JSample10_3.java 
$ java JSample10_3 
42634
89912
23551
77242
62438

まとめ

何かの役に立てばと。

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