0% found this document useful (0 votes)
38 views2 pages

Permutation 1234567890

This Java program takes a string as input from the user and prints out all possible permutations of that string. It uses a recursive method to iterate through each character position in the input string, add the character at that position to the output, and recursively call itself on the remaining substring to generate the remaining permutations, printing each one out.

Uploaded by

THONG878
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views2 pages

Permutation 1234567890

This Java program takes a string as input from the user and prints out all possible permutations of that string. It uses a recursive method to iterate through each character position in the input string, add the character at that position to the output, and recursively call itself on the remaining substring to generate the remaining permutations, printing each one out.

Uploaded by

THONG878
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1 import java.util.

*; 2 3 public class Permutations { 4 public static void main(String args[]) throws Exception { 5 Scanner input = new Scanner(System.in); 6 System.out.print("Enter String: "); 7 String chars = input.next(); 8 showPattern("", chars); 9 } 10 11 public static void showPattern(String st, String chars) { 12 if (chars.length() <= 1) 13 System.out.println(st + chars); 14 else 15 for (int i = 0; i < chars.length(); i++) { 16 try { 17 String newString = chars.substring(0, i) 18 + chars.substring(i + 1); 19 showPattern(st + chars.charAt(i), newString); 20 } catch (Exception e) { 21 e.printStackTrace(); 22 } 23 } 24 } 25 } 26

You might also like