public static String removeLeadingZeroes(String value):
Run Code Online (Sandbox Code Playgroud)
给定有效的非空输入,该方法应返回所有前导零被删除的输入.因此,如果输入是"0003605",则该方法应返回"3605".作为特殊情况,当输入仅包含零(例如"000"或"0000000")时,该方法应返回"0"
public class NumberSystemService {
/**
*
* Precondition: value is purely numeric
* @param value
* @return the value with leading zeroes removed.
* Should return "0" for input being "" or containing all zeroes
*/
public static String removeLeadingZeroes(String value) {
while (value.indexOf("0")==0)
value = value.substring(1);
return value;
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何为字符串"0000"编写代码.