public static String removeLeadingZeroes(String value):
给定一个有效的、非空的输入,该方法应返回删除所有前导零的输入。因此,如果输入是“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;
}
我不知道如何为字符串 "0000" 编写代码。
while
循环开始处添加一个if
语句来查找该条件。 - dsh