Page 643 - Computer science 868 Class 12
P. 643
Program 28 String Decoding
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. The first alphabet of each word must be in
capitals and rest will be small only. Any consecutive sets of code 32 will be taken as only one
blank space.
1 import java.io.*;
2 import java.util.*;
3 class coding
4 {
5 public static void main(String args[])throws IOException
6 { BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
7 String s="";
8 int ch1=32;
9 char c;
10 int i;
11 System.out.print("Input\t: ");
12 String cod=buf.readLine();
13 int length=cod.length();
14 int ch=0,a1=2,flag=0;
15 for (int a=0;a<=(length-1);)
16 { ch=(Integer.parseInt(cod.substring(a,a1)));
17 if(((ch>=65)&&(ch<=90))||(ch==32)||((ch>=97)&&(ch<=122)))
18 { if (ch1==32)
19 { ch=((ch>=65)&&(ch<=90))? ch:(ch-32);
20 if (ch==32)
21 continue; }
22 else
23 ch=((ch>=65)&&(ch<=90))? (ch+32):ch;
24 c=(char)ch;
25 s=s+c;
26 ch1=ch;
641
Internal Assessment 641

