我試圖驗證字段名稱是空的,它是工作字符串爲空
while(name.isEmpty()||!name.matches("^([A-Z*a-z]*(\\s))+[A-Z*a-z]*$"))
當我嘗試驗證字段數爲空時它給了一個錯誤。
while (number.charAt(0) != '0' || number.length() < 4 || !number.matches("^[0-9]*") || number.isEmpty())
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(Unknown Source)
空字符串' 「」'沒有任何字符,所以'的charAt(0)'將拋出'StringIndexOutOfBoundsException'。 – Pshemo
如何驗證字符串編號? – user1831131