I have an array of strings with products and values in it. Laid out like so:
ProductA 200
ProductB 50
ProductC 120
ProductD 1100
ProductE 5
I need to find the sum of all these numbers. The best I have been able to do is use this code to find the sum but it is finding the sum of each individual number:
for (char c : rdmPrize.replaceAll("\\D", "").toCharArray())
{
int digit = c - '0';
sum += digit;
if (digit % 2 == 0)
{
evenSum += digit;
}
}
The output it is giving me in this example would be 17, but I need it to be 1475.
Any ideas?
Thanks!