Page 319 - Computer science 868 Class 12
P. 319

16                  return;
                   17              }

                   18              String amtInWords = getAmtInWords(amt);
                   19              System.out.println(amtInWords);

                   20              System.out.println("Denomination:");
                   21              int t = amt;

                   22              for (int i = 0; i < notes.length; i++)
                   23              {
                   24                  int c = t / notes[i];

                   25                  if (c != 0)

                   26                       System.out.println(notes[i]  +  "\t*\t"  + c  +  "\t=\t"  + (c  *
                                              notes[i]));
                   27                  t = t % notes[i];
                   28              }

                   29          }
                   30          String getAmtInWords(int amt)

                   31          {
                   32              StringBuffer sb = new StringBuffer();

                   33               String  ar[]  =  {"Zero  ","One  ","Two  ","Three ","Four ","Five ","Six
                                     ","Seven ","Eight ","Nine ","Invalid digit"};
                   34              while (amt != 0)
                   35              {

                   36                  int d =  amt % 10;
                   37                  amt /= 10;

                   38                  if(d>=0 && d<=9)
                   39                      sb.insert(0, ar[d]);

                   40                  else
                   41                      System.out.println("Invalid digit");

                   42              }
                   43           return sb.toString();

                   44          }
                   45      }


                 The output of the preceding program is as follows:
                 Enter the amount: 12345
                 One Two Three Four Five





                                                                                                                       317
                                                                                                              Arrays   317
   314   315   316   317   318   319   320   321   322   323   324