/*------------------------------------------------------ 整数型変数の表示(桁数と書式) 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("変数kazuの値を表示します\n"); System.out.print(kazu); System.out.print("\n\n"); System.out.print("変数kazuの値を書式指定で示します\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"); } }