【发布时间】:2020-11-07 19:52:58
【问题描述】:
在此任务中,我需要使用生成的字符串数据来遍历其上的所有字符,然后仅对字符串中的数字求和。 例子:如果我们有这个数据字符串
5f395d07369071a505ef926527de2ac53e8c29e103dc63398315bc276224b81a
那么结果将是只取数字并将它们加在一起是2407
这是代码:
String studentId="22011151";
String studentName="Abed Alrahman Abuhilal";
int total=0;
String data =generateData(studentId); //here is a method I didn't show
这里有逻辑错误
for(int i=0; i < data.length(); i++) {
Boolean ok = Character.isDigit(data.charAt(i));
total+=data.charAt(i);
System.out.println("StudentId:"+studentId+" my name is:"+studentName+" total is:"+total);
【问题讨论】:
-
那么问题到底是什么?你有错误吗?结果错误?
-
得到 2407 是错误的还是需要得到 2407 作为答案?