我开始写这个算法:降价算法:串困难
public static String convert(String str) {
if (str.equals("# "))
return " ";
if (str.matches("#+.+")) {
int n = str.length() - str.replaceFirst("#+", "").length();
return "<h" + n + ">" + str.substring(n) + "<h" + n + ">";
}
return str;
}
}
所以,当我键入,####标题,它返回< H4>标题</H4>
我的问题是,当我写####标题###标题时,我希望它返回< h4>标题</h4> < h3>标题</h3>但它只返回< h4>标题</h4> ...我究竟做错了什么???
你的代码没有按没有给出所需的输出。并且有一个编译器错误。你使用'length'而不是'length()'和字符串。 –
yhea,好吧,我已经在我的回答 – breezee
中提到了“类似”,修正了上面的代码,编译和输出的权利。 – breezee