Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.example.blogservice;
public class CharReplacement {
public static void main(String[] args) {
String s = "AyxRTXra"; // ABBAAABB
System.out.println(convert(s));
}
private static String convert(String input) {
StringBuilder result = new StringBuilder();
char[] strings = input.toCharArray();
for (char c : strings) {
if (isUpperCase(c)) {
result.append("A");
} else {
result.append("B");
}
}
return result.toString();
}
private static boolean isUpperCase(char c) {
// A - Z = 65 - 90
// a - z = 97 - 122
return c >= 65 && c <= 90;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment