我正在处理一个递归方法,该方法将返回并在我的主方法中打印一个字符串,该字符串将为N递减1。删除一个字母对于字符串的每个递归。直到N变成1或者直到字符串有1个字母。 (N是在命令行上一个INT)递归方法打印字符串并递减1,并为每个递归删除1个字母
例如,如果我的命令行aruments是:5情人
它应该输出太:
5情人节,4 alentine,3 lentine, 2 intine,1 nt,
到目前为止,我设法倒计数在命令行参数输入的数字。我只是不知道如何去删除字符串中的一个字母? :○
到目前为止我的代码:
public static void main(String[] args){
int number = Integer.parseInt(args[0]);
String word = new String("");
word = args[1];
String method = recursive.method1(number);
System.out.println(method);
}
public static String method1(int number){
if (number < 0){
return "";
}
else{
return number + ", " + method1(number - 1);
}
}
你会希望将字符串传递给递归方法。在'String'类的文档中查找'substring'。 – Henry