-
Notifications
You must be signed in to change notification settings - Fork 0
/
GFG.java
31 lines (28 loc) · 910 Bytes
/
GFG.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Scanner;
class GFG {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String text = sc.next();
for (int i = 1; i <= n; i++) {
System.out.println(getOrdinalIndicator(i) + " " + text);
}
}
// Method to get the ordinal indicator for a given number
private static String getOrdinalIndicator(int number) {
if (number % 100 >= 11 && number % 100 <= 13) {
return number + "th";
} else {
switch (number % 10) {
case 1:
return number + "st";
case 2:
return number + "nd";
case 3:
return number + "rd";
default:
return number + "th";
}
}
}
}