Chapter 13 - Exercise 5

(5) For each of the basic conversion types in the above table, write the most complex formatting expression possible. That is, use all the possible format specifiers available for that conversion type.

package com.ciaoshen.thinkinjava.chapter13;
import java.math.*;
import java.util.*;

public class Exercise5{
    public static void main(String[] args) {
        Formatter f = new Formatter(System.out);
        char u = 'a';
        System.out.println("u = ‘a’");
        f.format("s: %1$-15.15s\n", u);
        // f.format("d: %d\n", u);
        f.format("c: %1$-15c\n", u);
        f.format("b: %1$-15.5b\n", u);
        // f.format("f: %f\n", u);
        // f.format("e: %e\n", u);
        // f.format("x: %x\n", u);
        f.format("h: %1$-15.5h\n", u);

Need Java Developers? Hire Me »

I know Java. Talk is cheap, watch my code.

I live in CANADA now.