概要
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
まとめ
何かの役に立てばと。