Skip to content

Instantly share code, notes, and snippets.

@daanta-real
Created October 5, 2021 22:50
Show Gist options
  • Save daanta-real/d3ff7f525592b9d06e90972d14e1e414 to your computer and use it in GitHub Desktop.
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
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