2.當這種情況發生時, 解決方案是將字串拆分為兩個, 確保字串中都沒有新行, 並將它們與 + 連線起來。因此, 您可以替換:原來:String s = "A very long string which just happens to go over the end of a line and causes a problem with the compiler";修改後String s = "A very long string which just happens to go over the end "+"of a line and causes a problem with the compiler"
3.編輯器會提示:String literal is not properly closed by a double-quote
4.當我們編譯時,報錯
Example.java:4: 錯誤: 未結束的字串文字
String s = "A very long string which just happens to go over
java錯誤Line nn: ";" expected處理方法:
1.這是因為字串換行了。有時你需要寫一個長字串。常見的錯誤是在字串中輸入了換行符。編譯器就會報錯:Line nn: ";" expected
2.當這種情況發生時, 解決方案是將字串拆分為兩個, 確保字串中都沒有新行, 並將它們與 + 連線起來。因此, 您可以替換:原來:String s = "A very long string which just happens to go over the end of a line and causes a problem with the compiler";修改後String s = "A very long string which just happens to go over the end "+"of a line and causes a problem with the compiler"
3.編輯器會提示:String literal is not properly closed by a double-quote
4.當我們編譯時,報錯
Example.java:4: 錯誤: 未結束的字串文字
String s = "A very long string which just happens to go over
^
Example.java:5: 錯誤: 需要";"
5.我們把多行拼接起來,再次編譯,就沒報錯了。