Permutations of a string

前端 未结 4 1765
遥遥无期
遥遥无期 2021-01-28 21:03
public class Permute {
    public static void main(String[] args) throws IOException {
        System.out.println(\"Enter a string\");
        BufferedReader bufReader =         


        
4条回答
  •  感情败类
    2021-01-28 21:54

    public class Permute {
        public static void main(String[] args) throws IOException {
            System.out.println("Enter a string");
            BufferedReader bufReader = new BufferedReader(new InputStreamReader(System.in));
            String text = bufReader.readLine();
            shuffle("",text);
        }
        public static void shuffle(String dummy, String input){
            if(input.length() <= 1)
                System.out.println(dummy+input);
            else{
                for(int i=0; i 

    It should be input.substring(i,i+1) instead of input.substring(i,1). Because each time I need only 1 character to be constant, which is at the beginning of the string and others have to be jumbled.

    The bug was I presumed the functionality of substring to be substring(beginIndex, length). But it is substring(beginIndex,endIndex).

    @Oli: Thank you for the help.

提交回复
热议问题