问题描述
请问大神这段代码哪里错了package备份;importjava.io.*;importjava.util.*;publicclasspllll备份{publicstaticvoidmain(String[]args)throwsException{BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));Stringp=br.readLine();dy(br,p);}publicstaticvoiddy(BufferedReaderbr,Stringp)throwsException{inti,j;Stringr=null,t=null;List<String>list=newArrayList<String>();Stringee=p;Stringq=null;//intk=ee.substring(0,1).length();for(i=0;i<p.length();i++){for(j=0;j<p.length();j++){if(i!=j){r=p.substring(i,i+1);t=ee.substring(j,j+1);q=r+t;list.add(q);//sop(q+"");}}}Iterator<String>iterator=list.iterator();while(iterator.hasNext()){ee=iterator.next();yy(ee,p);}}publicstaticvoidyy(Stringee,Stringp)throwsException{List<String>list=newArrayList<String>();inti,j;intk=2;Stringr=null,t=null,q=null;for(i=0;i<p.length();i++){r=p.substring(i,i+1);t=ee.substring(0,k);//asadsasddads,(0,2)就是1,2位的,每个(as)(ad)....都是1,2位的即sop(t+"");输出asadsasddadsq=r+t;list.add(q);sop(q+"");}Iterator<String>iterator=list.iterator();while(iterator.hasNext()){ee=iterator.next();if(k<p.length()+1){k++;yy(ee,p);}}}publicstaticvoidsop(Objectobj){System.out.print(obj);}}
解决方案
解决方案二:
字符串全排列问题,直接去翻算法书吧。
解决方案三:
还有中文的?