需要幫助將僞代碼轉換爲代碼。計算字符串中兩個字符之間的總字符數 - JAVA
如果在那裏有數據佔用,程序將接收輸入並打印出來。 因此,如果「:」之後什麼也沒有,那就會失敗。在這個例子中,理由之後沒有任何東西,所以測試會失敗,所有其他人都會通過。
我認爲最好的方法是檢查冒號後面的數據,看冒號和下一個冒號前的文本總長度之間是否有多於一個字符(空格)。因此,從理性到狀態檢查將輸入的
//This would be the check betweek the reason colon and status colon - 6 chars //becuase of the word status
if(lengthBetween_ReasoncolonAndStatusColon - 6 > 2){
//PASS
}else{
//fail
}
格式
User Name: Chris Smith [email protected] Users Password: 123ABC Last Login Date: 2015/10/14 - 12:30AM Reason: Status: Online
輸出
Username: PASS
Password: PASS
Last Login: PASS
REASON: FAIL
Status: PASS
代碼
//This would be the check betweek the username and password - 14 chars //becuase of the words User Password
if(lengthBetween_UsernameColonAndPasswordColon - 14 > 2){
//PASS, there must be data here
}else{
//fail, no data
}
任何幫助都可以。一個好的起點是向我展示如何解決兩個「關鍵」元素之間的總字符。所以我可以用代碼的一些幫助來說,前兩個冒號對之間有X個字符,下一個對之間有X個字符,依此類推。
謝謝!
您可以使用拆分()函數用冒號分割你的字符串,並把它放在一個列表/陣列。 http://stackoverflow.com/questions/10004066/java-splitting-an-input-file-by-colons – yogidilip
我想到了這一點,但這會截斷冒號前的信息。 – TJF
我想如果我說明這可能會起作用的字符丟失。 – TJF