0

Hi Everyone, I have a code that permutes Strings, it rather swaps them but I wanted the code to substitute strings, using permutiotions not swap them around...

Here is the sample code:

import java.util.*; 

public class PermutationExample { 
        public static void main(String args[]) throws Exception { 
                Scanner input = new Scanner(System.in); 
                System.out.print("Enter String: "); 
                String chars = input.next(); 
                showPattern("", chars); 
        } 

        public static void showPattern(String st, String chars) { 
                if (chars.length() <= 1) 
                        System.out.println(st + chars); 
                else 
                        for (int i = 0; i < chars.length(); i++) { 
                                try { 
                                        String newString = chars.substring(0, i) 
                                                        + chars.substring(i + 1); 
                                        showPattern(st + chars.charAt(i), newString); 
                                } catch (Exception e) { 
                                        e.printStackTrace(); 
                                } 
                        } 
        } 
}

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by NormR1
0

I wanted the code to substitute strings, using permutiotions

Could you show us what the code currently does and also show us what you want it to do with some examples?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.