[英]Convert this from Python into Java
How can I convert this into Java(Android) code? 如何将其转换为Java(Android)代码?
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. 但它不起作用我想将用户输入转换为数字数组,它们计算数组的总和。
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+");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.