/*--------------------------------------------------- 整数型変数の表示(桁数の指定)Print_int_keta (書式指定の方法) @先頭にimport文を入れる ADecimalFormat 変数名=new DecimalFormat("書式") 書式は # 0 , \\ など BSystem.out.print(変数名.format(表示したい数値)) ---------------------------------------------------*/ import java.text.*; class Print_int_keta { public static void main(String[] args) { int kazu; kazu=12345; System.out.print("変数の値をそのまま表示します\n"); System.out.print(kazu); System.out.print("\n\n"); System.out.print("変数の値を書式指定で表示します\n"); System.out.print("----+----1----+----2----+----3\n"); DecimalFormat fm1=new DecimalFormat("###,###"); // カンマ付き DecimalFormat fm2=new DecimalFormat("0000000000"); // ゼロで埋める DecimalFormat fm3=new DecimalFormat("\\#"); // 円記号 DecimalFormat fm4=new DecimalFormat("\\#,###"); // 円記号とカンマ System.out.print(fm1.format(kazu)); System.out.print("\n"); System.out.print(fm2.format(kazu)); System.out.print("\n"); System.out.print(fm3.format(kazu)); System.out.print("\n"); System.out.print(fm4.format(kazu)); System.out.print("\n"); } }