Last active 1748456953

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