sprintf in C & String.format in Java

可將字串插入可以變動的int
用for就可以產生一大批
ex. 1-01.txt, 1-02.txt, 1-03.txt ….等 很像但是有規則的字串
最常用在檔名處理上

sprintf in C:

sprintf(str, “%d”, num);
printf(“str = %sn”, str);

—————————————————————

String.format in Java:

// Store the formatted string in ‘result’
String result = String.format(“%4d”, i * j);
// Write the result to standard output
System.out.println( result );

作者

RongSon

Graduate Student of CCU COMM Game Development, Network Communication, macOS/Ubuntu/Android, Arduino/Raspberry Pi/Intel Edison, Java/Python/C/C++

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *