forked from Bhavya1912/Hackerrank-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaesarCipher.java
More file actions
30 lines (28 loc) · 818 Bytes
/
CaesarCipher.java
File metadata and controls
30 lines (28 loc) · 818 Bytes
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
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int size = in.nextInt();
String s = in.next();
int k;
int num = in.nextInt();
char a[] = new char[size];
for(int i=0;i<size;i++){
a[i] = s.charAt(i);
if(a[i]>=65 && a[i]<=90){
k = a[i] + num;
while(k>90 || k<65)
k-=26;
System.out.print((char)k);
}
else if(a[i]>=97 && a[i]<=122){
k = (int)a[i] + num;
while(k>122 || k<97)
k-=26;
System.out.print((char)k);
}
else
System.out.print(a[i]);
}
}
}