Page 647 - Computer science 868 Class 12
P. 647

5           {
                   6               Scanner sc = new Scanner(System.in);

                   7               String sortedStr = "",str,filstr = "";
                   8               int len,j,i;

                   9               char ch;
                   10              System.out.println("Enter a string:");

                   11              str = sc.nextLine();
                   12              str = str.toLowerCase();
                   13              len = str.length();

                   14

                   15              for (i = 'a'; i <= 'z'; i++)
                   16              {
                   17                  for (j = 0; j < len; j++)

                   18                  {
                   19                      ch = str.charAt(j);

                   20                      if (ch == (char)i)
                   21                      {

                   22                          sortedStr += ch;
                   23                      }

                   24                  }
                   25              }

                   26
                   27              System.out.println("Alphabetical order:");

                   28              System.out.println(sortedStr);
                   29

                   30              for (i = 0; i < sortedStr.length() - 1; i++)
                   31              {

                   32                  ch = sortedStr.charAt(i);
                   33                  filstr += ch;

                   34                  // if(ch==sortedStr.
                   35                  if(ch!=sortedStr.charAt(i+1))

                   36                  {
                   37                      for (j = (ch + 1); j < sortedStr.charAt(i+1); j++)







                                                                                                                       645
                                                                                                   Internal Assessment  645
   642   643   644   645   646   647   648   649   650   651   652