-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCipher.java
43 lines (43 loc) · 1.06 KB
/
Cipher.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.*;
public class Cipher
{
void convert(String str)
{
String s=str,r="";char ch;int a;
for(int i=0;i<s.length();i++)
{
ch=s.charAt(i);
a=(int)(ch);
if((a>=65&&a<=90))
{
if(a>=78)
r+=(char)(65+(a-78));
else
r+=(char)(78+(a-65));
}
else if((a>=97&&a<=122))
{
if(a>=110)
r+=(char)(97+(a-110));
else
r+=(char)(110+(a-97));
}
else if(ch=='!')
r+='?';
else
r+=ch;
}
System.out.println(r);
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string to be converted:");
String str=sc.nextLine();
Cipher obj=new Cipher();
if(str.length()>3)
obj.convert(str);
else
System.out.println("INVALID LENGTH");
}
}