Java - Write code to format int to string and pad 0 if needed

Requirements

Write code to format int to string and pad 0 if needed

Demo

//package com.book2s;
import java.text.DecimalFormat;

public class Main {
    public static void main(String[] argv) {
        int val = 42;
        System.out.println(int2char2(val));
    }/*from   w  ww .  j av a2  s .co m*/

    public static String int2char2(int val) {
        DecimalFormat fmt = new DecimalFormat("00");

        if ((val < 0) || (val > 99))
            return null;
        return fmt.format(val);
    }
}