Skip to content

Instantly share code, notes, and snippets.

@NguyenTatNhac
Created July 25, 2021 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NguyenTatNhac/d2d17877ce4d528fbd5583c477467f8a to your computer and use it in GitHub Desktop.
Save NguyenTatNhac/d2d17877ce4d528fbd5583c477467f8a to your computer and use it in GitHub Desktop.
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