Answer and Explanation
An array holds a fixed number of values of a single type. Its length is established when the array is created where the length is fixed after the creation.In c programming an array is a collection of data items all of them of the same type and accessed using a common name while in Java they are items that are dynamically created and all elements have the same type called the component type of the array.
//takes an array of int and returns an array of String the way you want!
public String[] setOrdinal(int[] arr)
{
String[] ord = new String[arr.length];
for(int i = 0; i < ord.length; i++)
{
ord[i] = convert(arr[i]);
}
return ord;
}
//takes a number and converts it to string and adds the proper letters
private String convert(int num)
{
if(num > 1000 || num <=0)
return "Not in range";
else if(num%10==0 || num%10==9 || num%10==8 || num%10==7 || num%10==6 || num%10==5 || num%10==4 || num%10==3)
{
return String.valueOf(num) + "th";
}
else if(num%10==2)
{
if((num/10)%10==1) //checks if the second digit is 1
return String.valueOf(num) + "th";
else
return String.valueOf(num) + "nd";
}
else
{
if((num/10)%10==1)
return String.valueOf(num) + "th";
else
return String.valueOf(num) + "st";
}
}