Reputation: 41
How can I convert this into Java(Android) code?
a = input()
asplit = a.split()
mapy = map(int, asplit)
suma = sum(mapy)
I've tried this:
EditText marks;
String value= marks.getText().toString();
String[] myList = value.split(" ");
int marksfinal=Integer.parseInt();
but it doesn't work I want to convert the user input which will be digits, into an array of digits, them calculate the sum of the array.
Upvotes: 2
Views: 141
Reputation: 93842
You just need a loop to sum all the values in the array.
int marksfinal=0;
for(String s : myList)
marksfinal += Integer.parseInt(s);
Also if you want to split on arbitratry width for whitespaces use :
String[] myList = value.split("\\s+");
Upvotes: 3