I have a string like
String str = "102, 308, 409.5";
and I want to add the numbers in the string 102+308+409.5 and keep the result in variable. How can I achieve that?Thanks
Note I was trying to convert the string to string array and then to int array in the below code, but doesn't works.
int sum = 0;
String[] arr = str.split(",");
int[] numArr = new int[arr.length];
for(int i=0; i<arr.length; i++){
numArr[i] = Double.parseDouble(arr[i]);
sum+=numArr[i];
}
int sumandint[] numArr- but you want to sum doubles!