Last active 1748456953

Revision 0726ee10ec4fc0fb064e10643a125a51a2d94b40

LetterChanges.java Raw
1import java.util.*;
2import java.io.*;
3
4class 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}
35