Question d’entretien chez Comcast

Write a program for the below. Input: ab Output: ab, ba Input: abc Output: abc, acb, bac, bca, cab, cbc

Réponse à la question d'entretien

Utilisateur anonyme

9 juil. 2018

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

2