Write a program for the below. Input: ab Output: ab, ba Input: abc Output: abc, acb, bac, bca, cab, cbc
Utilisateur anonyme
import java.util.Scanner; /** * Write a program for the below. Input: ab Output: ab, ba Input: abc Output: abc, acb, bac, bca, cab, cba * @author uspn */ public class StringPermutation { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter your test string : "); String str = sc.nextLine(); printPermutation(str); } private static void printPermutation(String str) { String result = ""; permutation(str, result); } private static void permutation(String str, String result) { if(str.length() == 0) { printString(result); } for(int i=0; i