You need to sign in to do that
Don't have an account?
fiona gentry
How To convert string into an integer by replacing each letter with its position in the alphabet
Dear folks,
Here is what i want to do
Hence ,Wrote a apex class for To convert string into an integer by replacing each letter with its position in the alphabet,but it doesnt seems working,error i get on Anonymus Console Window for below command
is
SDSAfterConvert.returnInteger();
Here is apex code
Regards,
Fiona
Here is what i want to do
For example, if s = "zbax" and k = 2, then the resulting integer would be 8 by the following operations: Convert: "zbax" ➝ "(26)(2)(1)(24)" ➝ "262124" ➝ 262124 Transform #1: 262124 ➝ 2 + 6 + 2 + 1 + 2 + 4 ➝ 17 Transform #2: 17 ➝ 1 + 7 ➝ 8
Hence ,Wrote a apex class for To convert string into an integer by replacing each letter with its position in the alphabet,but it doesnt seems working,error i get on Anonymus Console Window for below command
is
Line: 14, Column: 1 System.TypeException: Invalid integer: aHere is anonymous code
SDSAfterConvert.returnInteger();
Here is apex code
public class SDSAfterConvert { public static List<Integer> returnInteger(){ List<Integer> inputList = new List<Integer>(); String[] myAlphabets = new String[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'g'}; for (String s1 : myAlphabets) { System.debug(s1); Integer d = integer.ValueOf(s1); inputList.add(d); } return inputList; } }
Regards,
Fiona
Please try the below code:
Pass the String("zbax") and Transform #( 2 ) as input then you will get the final o/p as 8.
To execute the code from console use the below line:
Thanks,
Maharajan.C
All Answers
Please try the below code:
Pass the String("zbax") and Transform #( 2 ) as input then you will get the final o/p as 8.
To execute the code from console use the below line:
Thanks,
Maharajan.C