Page 547 - Cs_withBlue_J_C11_Flipbook
P. 547

i          int          To store the length of the sentence
                  len        int          Length of the word extracted
                  ch         char         Character extracted from the word



                   Program 24    An Encoded Text can be decoded by finding the actual character for the given ASCII Code in
                                 the encoded message.
                                 Write a program to input an encoded text having only sequence of ASCII values without
                                 any spaces. Any code or value which is not in range (65-90 or 97-122 or 32 for space) will be
                                 ignored and should not appear in the output message. Decode the encoded text and print in
                                 the form of a sentence.


                   1       import java.util.*;
                   2       class decoder

                   3       {
                   4           int l,c,b,m;
                   5           String x,w,w2,sub;

                   6           char ch2,ch;

                   7
                   8           decoder() // constructor
                   9           {

                   10              l=c=m=0;
                   11              x=w=w2=sub="";

                   12              ch2=ch=0;
                   13          }

                   14
                   15          void input() // inputing data from user

                   16          {
                   17              Scanner sc = new Scanner(System.in);

                   18              System.out.print("Enter the code:");
                   19              x=sc.nextLine();

                   20              l=x.length();
                   21          }

                   22
                   23          void compute() // decoding

                   24          {
                   25              for(int i=0;i<l;i++)





                                                                                                                       545
                                                                                                   Internal Assessment  545
   542   543   544   545   546   547   548   549   550   551   552