You need to sign in to do that
Don't have an account?
Ajay Kumar 583
Write the apex code to sort the n biggest numbers. input should be sent as a string with comma seperated values. the method should accept string of comma seperated numbers and a integer defining the value for n ?
Hi i need Apex code for this .
Greetings to you!
- I read your problem and implemented in Org. Please use the below code [Solved] : -
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha.
All Answers
Greetings to you!
- I read your problem and implemented in Org. Please use the below code [Solved] : -
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha.
Thanks for replying. As i was new to Apex ,I needed only a simple Apex class and a method which will accept a string of numbers and returning the Biggest number. I have modified the above code to the simplest as below:
public class findBiggestValueClass {
public static integer sortSlctRec(String stringToSort)
{
String sortString = stringToSort;
List<String> sortList = sortString.split(',');
List<integer> intList = new List<integer>();
for(String s : sortList){
intList.add(integer.valueOf(s));
}
intList.sort();
System.debug('The given List is :'+intList);
System.debug('The Biggest number is :'+intList[intList.size()-1]);
return intList[intList.size()-1];
}
}
Now i need a integer defining the value for n ? Like for
eg: if n = 2 display first two biggest number in the List.
Thanks,
Ajay