Created
July 25, 2021 12:09
-
-
Save NguyenTatNhac/d2d17877ce4d528fbd5583c477467f8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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