disha
| Subject: ISC practical program Mon Feb 22, 2010 1:09 am | |
| We need to write a program which prints all possible anagrams of a word. And the maximum length of the word should be 7. I think it had come in isc a few years ago, i dont remember which year though. Can anyone please tell me how to do it. I dont have a clue.. |
|
saif Active member
| Subject: Re: ISC practical program Mon Feb 22, 2010 10:40 am | |
| if analgam means All possible permotations of a string then here is the program import java.io.*; public class Permute { public static void swap(char[] set, int first, int second) //java doesn't allow the same pass by reference like C++ { char ch = set[second]; //so we pass the char array and assign, since this will hold set[second] = set[first]; //swap the values set[first] = ch; } public static int permute(char[] set, int begin, int end) { int i; int range = end - begin; if (range == 1) { System.out.println(set); //print out each permutation } else { for(i=0; i<range; i++) { swap(set, begin, begin+i); //initial swap permute(set, begin+1, end); //recursion swap(set, begin, begin+i); //swap back } } return 0; } //***************TEST EXAMPLE******************** public static void main(String[] args) { char[] test = {'a','b','c','d'}; permute(test, 0, 4); } } |
|
disha
| Subject: Re: ISC practical program Mon Feb 22, 2010 11:26 pm | |
| thanks a lot! |
|
sayan822
| Subject: Re: ISC practical program Tue Feb 23, 2010 12:46 am | |
| hi...can u plz help me out in this??? WAP to input a sentence and input any word number/numbers of the sentence. Replace only those words present at integer places by the next character in circular fashion. example : Input sentence : He has good Books. Input integer : 2, 4. Output sentence: He ibt good Cpplt. |
|
Sponsored content
| Subject: Re: ISC practical program | |
|
|
|