请问这段代码怎么修改使它变成输出结果为有换行的:
例如:
原始字符串是"abc",打印得到下列所有组合情况
"a" "b" "c"
"ab" "bc" "ca" "ba" "cb" "ac"
"abc" "acb" "bac" "bca" "cab" "cba"
public static void main(String[] args) throws Exception{
InputStream is = System.in;
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
char[] c = s.toCharArray();
String[] sa = new String[c.length];
ArrayList<String> al = new ArrayList<String>();
for (int i = 0; i < sa.length; i++) {
sa = String.valueOf(c.clone());
al.add(sa);
}
while(al.get(al.size()-1).length()!=sa.length){
ArrayList<String> al2 = new ArrayList<String>();
for (int i = 0; i < sa.length; i++) {
String s2;
for (String s3:al) {
if(!s3.contains(sa) && s3.length()==al.get(al.size()-1).length()){
s2 = sa+s3;
al2.add(s2);
}
}
}
for(String s4: al2){
al.add(s4);
}
}
for(String s5:al){
System.out.print(s5+"\t");
}
}
}
|