String s contains an abbreviated ordinal number such as "3rd", "99th", "973rd". Write code that sets the int value to the corresponding int (3, 99, 973, in the examples just given).
Test Cases
Test case #1
Expected result: value is 1
Test case #2
Expected result: value is 200
Test case #3
Expected result: value is 22
Test case #4
Expected result: value is 53
Please find the program and its output below.
In java :
public class Main
{
public static void main(String[] args) {
String[] s={"1st", "200th", "22nd", "53th",
"973rd"};
for (int i=0;i<s.length;i++){
s[i]=s[i].replace("rd","");
s[i]=s[i].replace("th","");
s[i]=s[i].replace("st","");
s[i]=s[i].replace("nd","");
System.out.println(s[i]);
}
}
}
Get Answers For Free
Most questions answered within 1 hours.