Tuesday 20 September 2011

Encoding & Decoding using Java

import java.io.*;
public class EncodingDecoding
{
  public static void main(Strng args[])throws IOException
  {
   BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
   System.out.print("Enter a word: ");
   String s= b.readLine();
   System.out.print("Enter the number of moves: ");
   int i, m= Integer.paresInt(b.readLine());
  for(i=0;i<s.length;i++)
  {
     int ch;
     ch=s.charAt(i)+m;
     while(ch>90)
         ch=ch-26;
     while(ch<65)
         ch=ch+26;
   System.out.println((char)ch+" ");
  }
}
}

No comments:

Post a Comment