aarthi Active member
| Subject: ISC 2004 question on decoding Tue Feb 23, 2010 5:54 pm | |
|
Can anyone give me the algorithm for this question. Its taken from ISC 2004 computer practical question paper.
Thanks. |
|
diptojit Active member
| Subject: Re: ISC 2004 question on decoding Tue Feb 23, 2010 11:21 pm | |
| Hope this helps you @ Aarthi Here's the program.....
// ISC 2004 Q2 // To accept a string of integers and reverse them.Then to extract out meaningful ASCII codes // of capital and small alphabets and also including spaces. import java.io.*; class ISC_2004_decoder { int i; String rev(String s)// returns reversed string { String s1="";int ln; ln=s.length(); for(i=0;i<ln;i++) { s1=s.charAt(i)+s1; } return(s1); } char asc(int a)// returns character corresponding to ASCII code { char ch; ch=(char)(a);// explicit conversion of Integer to Character return(ch); } int meaning(int b)// checks whether ASCII code is meaningful or not { int mn=0; if((b>=65&&b<=90)||(b>=97&&b<=122)||(b==32)) { mn=1;} return(mn); } void main()throws IOException { int ln1,asint;char ch1;String s2="",srev; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter message to be decoded"); String st=in.readLine();// accepting integers in the form of a string ln1=st.length(); System.out.println("The Decoded message is :"); srev=rev(st); for(i=0;i<ln1;i++) { ch1=srev.charAt(i); s2=s2+ch1; asint=Integer.parseInt(s2); if(meaning(asint)==1)// calling function meaning() to find out whether asint is a valid ASCII code { System.out.print(asc(asint));// calling function asc() to get the character with code integer asint s2=""; } } } } |
|
aarthi Active member
| Subject: ISC 2004 question on decoding Wed Feb 24, 2010 7:23 pm | |
| Thanks a lot diptojit. Both your codes have been very useful! They are very simply yet efficient. Thanks a lot! |
|
Sponsored content
| Subject: Re: ISC 2004 question on decoding | |
|
|
|