Write a program to print all permutations of string?



Write a program to print all permutations of string?..

Answer / Md Hasan Ahmad

Here is an example implementation using recursion:n```javanvoid printPermutations(String str, int l, int r) {n if (l == r) {n System.out.println(str);n return;n }n for (int i = l; i <= r; i++) {n str = swap(str, l, i);n printPermutations(str, l+1, r);n str = swap(str, l, i);n }n}nString swap(String str, int i, int j) {n char temp; temp = str.charAt(i);n str = str.substring(0, i) + str.substring(j, i) + str.substring(j+1, i+1) + str.substring(0, j);n return str;n}n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

How do I write a self declaration?

1 Answers  


What is java and why do we need it? Explain

1 Answers  


What are data types in programming?

1 Answers  


how to create multithreaded program? Explain different ways of using thread? : Java thread

1 Answers  


Explain the difference between a Thread and a Process.

1 Answers   Ciena,


What is structure of java heap? What is perm gen space in heap?

1 Answers  


What are computer functions?

1 Answers  


Can we call the constructor of a class more than once for an object?

1 Answers  


How will you get the platform dependent values like line separator, path separator, etc., ?

1 Answers  


What is string in java? String is a data type?

1 Answers  


Convert Binary tree to linked list.

1 Answers   Amazon,


What code optimizations techniques you follow in general practice?

2 Answers   Accenture, TCS, Wipro,


Categories