BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #43317同步于 2015/8/2
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

如何输出字符串的所有组合

shuoshu
2015/8/2镜像同步1 回复
例如,输入字符串“abc”,输出a,b,c,ab,ac,bc,abc。下面是程序,求问红色部分是什么意思? public class StringPrint { public static void main(String[] args) { String s = "abc"; StringPrint(s); } public static void StringPrint(String s) { char[] c = s.toCharArray(); if(c == null) return; int len = c.length; boolean[] used = new boolean[len]; char[] cache = new char[len]; int result = len; while(true) { int index = 0; while(used[index]) { used[index] = false; ++result; if(++index == len) return; } used[index] = true; cache[--result] = c[index]; System.out.print(new String(cache).substring(result) + " "); } } }
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复
shuoshu机器人#1 · 2015/8/3
up