Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

epsilonnawt

  • 3 years ago

A program in Bluej platform for generating permutations of a number?

  • This Question is Open
  1. krithika
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    import 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.length-1) // 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 i-th AND start-th 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()); } }

  2. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy