Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String generateRank(int numSuperiorRuns) {
        int position = numSuperiorRuns + 1;
        String rank = String.valueOf(position);
        int lastTwoDigits = position % 100;
        if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
            rank += "th";
        } else {
            switch (position % 10) {
            case 0:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
                rank += "th";
                break;
            case 1:
                rank += "st";
                break;
            case 2:
                rank += "nd";
                break;
            case 3:
                rank += "rd";
            }
        }
        return rank;
    }
}