-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShiftFollowIndex.java
More file actions
36 lines (36 loc) · 1.3 KB
/
Copy pathShiftFollowIndex.java
File metadata and controls
36 lines (36 loc) · 1.3 KB
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
public class ShiftFollowIndex {
public static void main(String[] args) {
java.util.Scanner sc=new java.util.Scanner(System.in);
System.out.print("Enter a letter : ");
String letter=sc.nextLine();
while(letter.length()<=0 || letter.length()>300){
System.out.print("Try again ! , Enter a letter : ");
letter=sc.nextLine();
}
char [] forShift=letter.toCharArray();
for(int i=0;i<forShift.length;i++){
switch(forShift[i]){
case '^':
case '&':
case '#':
case '@':
case '*':
case '(':
case '!':
case '/':
case ' ': System.out.print(forShift[i]); break;
default :
if(!Character.isLowerCase(forShift[i]) && (forShift[i]+i)>90){
System.out.print((char)(((forShift[i]+i)-65)%26+65));
}
else if(Character.isLowerCase(forShift[i]) && (forShift[i]+i)>122){
System.out.print((char)(((forShift[i]+i)-97)%26+97));
}
else{
System.out.print((char)(forShift[i]+i));
}
break;
}
}
}
}