A community for students.
Here's the question you clicked on:
 0 viewing
epsilonnawt
 2 years ago
A program in Bluej platform for generating permutations of a number?
epsilonnawt
 2 years ago
A program in Bluej platform for generating permutations of a number?

This Question is Open

krithika
 2 years ago
Best ResponseYou've already chosen the best response.0import java.util.*; public class Permutation { static Scanner sc=new Scanner(System.in); public char[] arr; public int count; public Permutation(String word) { arr=word.toUpperCase().toCharArray(); count=0; } public void permute(int start) { if(start==arr.length1) // TRIVIAL CASE { System.out.print(arr);System.out.print(" "); if((getCount()+1)%5==0)System.out.println(); count++; return; } for(int i=start;i<arr.length;i++) { // SWAPPING ith AND startth ELEMENT char temp=arr[i]; arr[i]=arr[start]; arr[start]=temp; permute(start+1); // SWAPPING TO ORIGINAL POSITION temp=arr[i]; arr[i]=arr[start]; arr[start]=temp; } } public int getCount(){ return count; } public static void main(String args[]) { System.out.print("Enter The Word : "); String word=sc.next(); System.out.println(); Permutation obj=new Permutation(word); obj.permute(0); // BEGIN WITH 1ST CHAR System.out.println("\nTotal No Of Permutation : "+obj.getCount()); } }
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.