IOapalooza7.java
Select all
/* IOapalooza7.java CIS 260 David Klick 2006-01-18 This program demonstrates numeric output formatting using the DecimalFormat class. */ import java.text.DecimalFormat; public class IOapalooza7 { public static void main(String[] args) { // demonstration of DecimalFormat class double x = 123.456789; double y = 987; double z = .75; DecimalFormat[] df = new DecimalFormat[10]; df[0] = new DecimalFormat("####"); df[1] = new DecimalFormat("####.####"); df[2] = new DecimalFormat("0000.0000"); df[3] = new DecimalFormat("0000.00000000"); df[4] = new DecimalFormat("###;-###"); df[5] = new DecimalFormat(" ###;-###"); df[6] = new DecimalFormat("##.##"); df[7] = new DecimalFormat("##.##%"); System.out.println("DecimalFormat demos:"); System.out.println(df[0].format(x)); System.out.println(df[1].format(x)); System.out.println(df[2].format(x)); System.out.println(df[3].format(x)); System.out.println(df[4].format(y)); System.out.println(df[4].format(-y)); System.out.println(df[5].format(y)); System.out.println(df[5].format(-y)); System.out.println(df[6].format(z)); System.out.println(df[7].format(z)); } }