Page 363 - Computer science 868 Class 12
P. 363
16 for (j = 0; j < len; j++)
17 {
18 ch = str.charAt(j);
19 if (ch == (char)i)
20 {
21 sortedStr += ch;
22 }
23 }
24 }
25 System.out.println("Alphabetical order:");
26 System.out.println(sortedStr);
27 for (i = 0; i < sortedStr.length() - 1; i++)
28 {
29 ch = sortedStr.charAt(i);
30 filstr += ch;
31 //if(ch==sortedStr.
32 if(ch!=sortedStr.charAt(i+1))
33 {
34 for (j = (ch + 1); j < sortedStr.charAt(i+1); j++)
35 {
36 filstr += (char)j;
37 }
38 }
39 }
40 filstr += sortedStr.charAt(sortedStr.length() - 1);
41 System.out.println("Filled String:");
42 System.out.println(filstr);
43 }
44 }
The output of the preceding program is as follows:
Enter a string:
india is great
Alphabetical order:
aadegiiinrst
Filled String:
aabcdefghiiijklmnopqrst
361
Strings 361

