GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — java-basics/java-programs/Permutation.java at master · learning-zone/java-basics Expand file tree/ Copy pathPermutation.javaMore file actions 31 lines (27 loc) · 791 Bytes / Copy pathPermutation.javaFile metadata and controls31 lines (27 loc) · 791 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 package misc; /** * Algorithm:- * 1. Try each of the letters in turn as the first letter and * then find all the permutations of the remaining letters using a recursive call. * 2. The base case is when the input is an empty string the only permutation is the empty string. * */ public class Permutation { public static void permutation(String str) { permutation("", str); } private static void permutation(String prefix, String str) { int n = str.length(); if (n == 0) System.out.println(prefix); else { for (int i = 0; i < n; i++) permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i + 1, n)); } } public static void main(String[] args) { String str = "ABC"; Permutation obj = new Permutation(); obj.permutation(str); } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |