View Code of Problem 447

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in =new Scanner(System.in);
		int t =in.nextInt();
		for(int i =0;i<t;i++) {
			int n =in.nextInt();
			if((n/10)%10==1) {
				System.out.println(n+"th");
			}else {
				if(n%10==1) {
					System.out.println(n+"st");
				}else if(n%10==2){
					System.out.println(n+"nd");
				}else if(n%10==3){
					System.out.println(n+"rd");
				}else {
					System.out.println(n+"th");
				}
			}
		}
	}

}

Double click to view unformatted code.


Back to problem 447