Created
October 5, 2021 22:50
-
-
Save daanta-real/d3ff7f525592b9d06e90972d14e1e414 to your computer and use it in GitHub Desktop.
Changes the string values to * the position after all of 'n'th characters
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
public class Main { | |
// Returns the string which changed all characters after 'n'th to * | |
public static String strToStar(String s, int n) { | |
return s.substring(0, n) | |
+ new String(new char[s.length() - n]) | |
.replace("\0", "*"); | |
} | |
// Test | |
public static void main(String[] args) { | |
String result = strToStar("abcdefg", 2); | |
$.pn(result); | |
} | |
} | |
[Result] | |
ab***** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment