-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShiftWords.java
More file actions
36 lines (36 loc) · 1.19 KB
/
Copy pathShiftWords.java
File metadata and controls
36 lines (36 loc) · 1.19 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 ShiftWords {
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(char e : forShift){
switch(e){
case '^':
case '&':
case '#':
case '@':
case '*':
case '(':
case '!':
case '/':
case ' ': System.out.print(e); break;
default :
if(!Character.isLowerCase(e) && (e+3)>90){
System.out.print((char)(((e+3)-65)%26+65));
}
else if(Character.isLowerCase(e) && (e+3)>122){
System.out.print((char)(((e+3)-97)%26+97));
}
else{
System.out.print((char)(e+3));
}
break;
}
}
}
}