「Java入門」java.lang.String.format()のサンプル
Javaコード
package com.itstudy;
public class StrfmtDemo {
public static void main(String[] args) {
String ctn = String.format(“%s-> %s-> %s", “it", “change", “world");
String ctn2 = String.format(“%dx%dx%d", 11, 22, 33);
String ctn3 = String.format(“%2d", 8);
String ctn4 = String.format(“result->%2s:%2d", “test11", 85);
System.out.println(ctn);
System.out.println(ctn2);
System.out.println(ctn3);
System.out.println(ctn4);
}
}
結果:
it-> change-> world
11x22x33
8
result->test11:85