Active IQ Unified Manager Discussions
Active IQ Unified Manager Discussions
Hello,
I am trying to write a function which will sum all the Elements in an array...
def arrayElementSum(str)
{
String[] splitArray = str.split(",");
for(i=0; i<splitArray.length; i++) {
(int)myTotal += splitArray[i];
}
return myTotal;
}
This function is not working, can someone please have a look at it and see whats wrong init.
,Sheel
Try this:
def arrayElementSum(str)
{
String[] splitArray = str.split(",");
int i = 0;
int myTotal = 0;
for (i = 0; i< splitArray.length; i++) {
myTotal += (int) splitArray[i];
}
return myTotal;
}
Hello,
I tried it but when testing it get the following:
Expression: - arrayElementSum("10")
Result: - 0class java.lang.Integer
Expression:- arrayElementSum("10,10")
Result: - 0class java.lang.Integerclass java.lang.Integer
Any Idea, how can we solve this.
,Sheel
Which WFA version are you using ? The function code which I pasted earlier is working on my WFA server version 2.2.1.0.0RC1.
You can try using Integer.parseInt instead of casting to int while adding the myTotal.
Thanks it worked for me,