Page 380 - Computer science 868 Class 12
P. 380
72 obj.display();
73 }
74 }
The output of the preceding program is as follows:
Enter the word:India
Frequency of vowels: 3
Frequency of consonants: 2
Original word:INDIA
Rearranged word:IIAND
Program 10 Write a program in Java to accept a four-letter word. Display all the probable four-letter
combinations such that no letter should be repeated in the output within each combination.
Sample Input:
PARK
Sample Output:
PAKR, PKAR, PRAK, APRK, ARPK, AKPR, and so on.
1 import java.util.*;
2 class combination
3 {
4 void change(String str, int l, int r)
5 {
6 if (l == r)
7 System.out.println(str);
8 else
9 {
10 for (int i = l; i <= r; i++)
11 {
12 str = swap(str,l,i);
13 change(str, l+1, r);
14 str = swap(str,l,i);
15 }
16 }
17 }
18 String swap(String a, int i, int j)
19 {
378378 Touchpad Computer Science-XII

