Method
swap
(String mystring, int i, int j)
Source from the content-addressed store, hash-verified
| 1 | import java.util.*; |
| 2 | class Permutation { |
| 3 | static String swap(String mystring, int i, int j) // function to swap the characters in the string |
| 4 | { |
| 5 | char ch[] = mystring.toCharArray(); |
| 6 | char tempo = ch[i]; |
| 7 | ch[i] = ch[j]; |
| 8 | ch[j] = tempo; |
| 9 | return String.valueOf(ch); |
| 10 | } |
| 11 | static void permutation(String s, int index) // To permuatate the string |
| 12 | { |
| 13 | if (index == s.length() - 1) // if the index equals the length, print the string |
Tested by
no test coverage detected