英文:
I recieve this error when i compile my java file: This method must return a result of type String
问题
I try both return and System.out.println() but nothing have changed, help please.
答案1
得分: 1
我认为你只希望在未找到任何数字时返回 null。因此,将第49行的 return null 移动到for循环的 } 后的第51行。
发布的代码永远不会达到 i=1,因为循环总是在第一次迭代中返回。
错误告诉你,存在一种情况,方法在没有 return 语句的情况下结束。例如,如果 cpt=0,就是这种情况。
英文:
I think you want to return null only if no number is found. So move the return null in line 49 to line 51 after the } of the for-loop.
The posted code never reaches i=1, because the loop always returns in the first iteration.
The error tells you, that cases exists where the method ends without a return statement. This is the case if cpt=0, for example.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论