Java tutorial
//package com.java2s; public class Main { private static String dateFormatHelper(String dayNum) { String digit = ""; if (dayNum.charAt(0) == '0') { digit += dayNum.charAt(1); return digit + dateFormatHelpersHelper(digit); } else return dayNum + dateFormatHelpersHelper(dayNum); } private static String dateFormatHelpersHelper(String day) { switch (day) { case "1": case "21": case "31": return "st"; case "2": case "22": return "nd"; case "3": case "23": return "rd"; default: return "th"; } } }