
write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string
ex:If a user enters a numbered value in a text field, like 1 or 2 or 3 or 4 the o/p should appear as 1st or 2nd or 3rd or 4th.

Hi Friend,
Try the following code:
public class OrdinalNumber {
public static String ordinalNo(int value) {
int hunRem = value % 100;
int tenRem = value % 10;
if (hunRem - tenRem == 10) {
return "th";
}
switch (tenRem) {
case 1:
return "st";
case 2:
return "nd";
case 3:
return "rd";
default:
return "th";
}
}
public static void main(String[] args) {
OrdinalNumber number = new OrdinalNumber();
for (int i = 1; i <= 10; i++) {
String st = number.ordinalNo(i);
System.out.println(i + " = " + i + st);
}
}
}
Thanks

Thank you
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.