You are on page 1of 4

Qn.

Coding

2003 Question 2

import java.io.*;

class Code

String s;

int l;

int shift;

String code="";

public void input()throws IOException

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the coded text (characters less than 100) : ");

s=br.readLine();

l=s.length();

if(l>100)

System.out.println("Character limit exceeded");

System.exit(0);

s=s.trim()+" ";

System.out.println("Shift value :");

shift=Integer.parseInt(br.readLine());

if(shift>26)
{

System.out.println("INPUT: "+s);

System.out.println("INVALID SHIFT VALUE");

System.exit(0);

public void calc()

for(int i=0;i<l;i++)

int p='Q'+shift;

if(p>90)

p=64+(p-90);

if(((i+1))<l&&(s.charAt(i)==(char)p)&&(s.charAt(i+1)==(char)p))

code=code+" ";

i++;

else

char k=s.charAt(i);

if(Character.isUpperCase(k))

int t=k-shift;

if(t<65)
{

t=91-(65-t);

code=code+(char)t;

else

code=code+(char)t;

public void display()

System.out.println("INPUT: "+s);

System.out.println("\t\t\tShift : "+shift);

System.out.println("OUTPUT: "+code);

public void main()throws IOException

input();

calc();

display();

}
OUTPUT

Enter the coded text (characters less than 100) :

KPKPRRDIBSMFTRRYBWJFS

Shift value :

INPUT: KPKPRRDIBSMFTRRYBWJFS

Shift : 1

OUTPUT: JOJO CHARLES XAVIER

You might also like