我試圖解決Leetcode 中的一個問題,討論的解決方案之一如下:public class Solve { public static void main(String[] args) { String haystack = "mississippi"; String needle = "issip"; System.out.println(strStr(haystack,needle)) ; } public static int strStr(String haystack, String needle) { for (int i = 0; ; i++) { for (int j = 0; ; j++) { if (j == needle.length()) return i; if (i + j == haystack.length()) return -1; if (needle.charAt(j) != haystack.charAt(i + j)) break; } } }}編譯器不應該在這里拋出“無返回語句”錯誤嗎?
為什么編譯器不拋出“無返回語句”的錯誤?
慕的地6264312
2021-11-03 16:08:56
