public static String ordinalize ( int number ) { int modulo = number % 100 ; if ( modulo >= 11 && modulo <= 13 ) return number + "th" ; switch ( number % 10 ) { case 1 : return number + "st" ; case 2 : return number + "nd" ; case 3 : return number + "rd" ; default : return number + "th" ; } }
Turns a non - negative number into an ordinal string used to denote the position in an ordered sequence such as 1st 2nd 3rd 4th