LetterChanges.java
· 974 B · Java
Raw
//Letter changes
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 | //Letter changes |
2 | import java.util.*; |
3 | import java.io.*; |
4 | |
5 | class 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 |