ProtyayMnd50 revised this gist . Go to revision
1 file changed, 1 insertion
LetterChanges.java
@@ -1,3 +1,4 @@ | |||
1 | + | //Letter changes | |
1 | 2 | import java.util.*; | |
2 | 3 | import java.io.*; | |
3 | 4 |
ProtyayMnd50 revised this gist . Go to revision
1 file changed, 34 insertions
LetterChanges.java(file created)
@@ -0,0 +1,34 @@ | |||
1 | + | import java.util.*; | |
2 | + | import java.io.*; | |
3 | + | ||
4 | + | class Main { | |
5 | + | public static String LetterChanges(String str) { | |
6 | + | StringBuilder result = new StringBuilder(); | |
7 | + | ||
8 | + | for (char c : str.toCharArray()) { | |
9 | + | if (Character.isLetter(c)) { | |
10 | + | // Shift letter | |
11 | + | if (c == 'z') { | |
12 | + | c = 'a'; | |
13 | + | } else if (c == 'Z') { | |
14 | + | c = 'A'; | |
15 | + | } else { | |
16 | + | c = (char)(c + 1); | |
17 | + | } | |
18 | + | ||
19 | + | // Capitalize vowels | |
20 | + | if ("aeiou".indexOf(c) >= 0) { | |
21 | + | c = Character.toUpperCase(c); | |
22 | + | } | |
23 | + | } | |
24 | + | result.append(c); | |
25 | + | } | |
26 | + | ||
27 | + | return result.toString(); | |
28 | + | } | |
29 | + | ||
30 | + | public static void main(String[] args) { | |
31 | + | System.out.println(LetterChanges("hello*3")); // Output: Ifmmp*3 | |
32 | + | System.out.println(LetterChanges("fun times!")); // Output: gvO Ujnft! | |
33 | + | } | |
34 | + | } |