LetterChanges.java
· 957 B · Java
Raw
import java.util.*;
import java.io.*;
class Main {
public static String LetterChanges(String str) {
StringBuilder result = new StringBuilder();
for (char c : str.toCharArray()) {
if (Character.isLetter(c)) {
// Shift letter
if (c == 'z') {
c = 'a';
} else if (c == 'Z') {
c = 'A';
} else {
c = (char)(c + 1);
}
// Capitalize vowels
if ("aeiou".indexOf(c) >= 0) {
c = Character.toUpperCase(c);
}
}
result.append(c);
}
return result.toString();
}
public static void main(String[] args) {
System.out.println(LetterChanges("hello*3")); // Output: Ifmmp*3
System.out.println(LetterChanges("fun times!")); // Output: gvO Ujnft!
}
}
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 | } |
35 |