如何解决递归方法排列的理解
正如标题所述,我正在寻找一些帮助来了解所附代码中发生的事情。具体来说,为什么在'(“”,s)'中使用引号 (String s1,String s2)是怎么回事,这是在实例化字母的地方吗?
最后,到底displayPermutaion方程到底发生了什么?
感谢您抽出宝贵的时间来提供帮助,我真的很感谢!
public static void main(String[] args)
{
System.out.print("Please enter your phrase here: ");
String s = new Scanner(System.in).next();
System.out.println("All the permutations of your phrase are listed below:\n" + s);
displayPermutation(s);
}
public static void displayPermutation(String s)
{
displayPermutation("",s);
}
public static void displayPermutation(String s1,String s2)
{
if (s2.length() == 0)
{
System.out.println(s1);
}
else
{
for (int i = 0; i < s2.length(); i++)
{
displayPermutation(s1 + s2.charAt(i),s2.substring(0,i) + s2.substring(i+1));
}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。