今天我收到了這個採訪問題。有人可以幫我解決這個問題嗎?隨機字符串的整數之和
/**
* Return the sum of all integers from a random string. Continuous Integers must be considered as one number.
* Given the following inputs, we expect the corresponding output:
*
* "1a2b3c" ==>6 (1+2+3)
* "123ab!45c" ==> 168 (123+45)
* "abcdef" ==> 0 (no integers in String)
* "0123.4" ==> 127 ()
* "dFD$#[email protected]#T1234;/..10" => 1279 (23+12+1234+10)
* "12a-10b" => 2 (12-10)
*/
private static long SumOfNumbers (String str){
return null;
你是怎樣嘗試去解決呢?你在哪裏被封鎖? – Codebender
也許一個'Scanner'可以幫忙,或者一個正則表達式來分割'String'或一個'for-loop' .... – MadProgrammer
可能重複 - http://stackoverflow.com/questions/28227772/return-the- sum-of-all-integers-from-a-random-string-without-using-regex –