I recieve this error when i compile my java file: This method must return a result of type String

huangapple go评论75阅读模式
英文:

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.

英文:

code source:

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.

huangapple
  • 本文由 发表于 2023年3月21日 00:00:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75792594.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定