//The following three lines are needed to get a number from the keyboard. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class FourWayOrdinal { public static void main(String[] args) { System.out.print("Please type a number: "); int i = getInt(); System.out.print("The ordinal form of the number is " + i); if (i == 1) { System.out.print("st"); } else if (i == 2) { System.out.print("nd"); } else if (i == 3) { System.out.print("rd"); } else { System.out.print("th"); } System.out.println(); } //The following 16 lines are needed to get a number from the keyboard. private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); private static int getInt() { try { return Integer.parseInt(reader.readLine()); } catch (IOException e) { System.err.println("Couldn't receive input: " + e.getMessage()); } catch (NumberFormatException e) { System.err.println(e.getMessage() + ", the characters were not a number."); } return 0; } }