Mask all the characters except last 4 digit/character

 

Questions: WAP to mask all the character of string except last 4 characters

Eg: 12324324234354          ##########4354

       1213                                                  1223

        1                                                        1

    spotify                              ###tify


Solution:                              

public class Mask {
public static String maskify(String cc) {
String str="";
if(cc.length()<=4)
return cc;


for(int i=cc.length()-5;i>=0;i--) {
str=str+"#";
}
str=str+cc.substring(cc.length()-4,cc.length());
return str;
}

public static void main(String[] args) {
System.out.println(maskify("54321"));
}
}

Comments

Popular posts from this blog

Get first non-repeating Letter

Cypress run command

Docker commands