-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreditCardMask.java
More file actions
42 lines (28 loc) · 1.1 KB
/
CreditCardMask.java
File metadata and controls
42 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package LogicalPrograms;
public class CreditCardMask {
public static String Maskify(String str) {
if (str.length() < 4) {
return str;
}
else {
String res = "";
for (int i = 0; i < str.length(); i++) {
if (i < str.length() - 4) {
res += "#"; //#### #### ####
}
}
res += str.substring(str.length() - 4); //5616
return res; //#### #### #### 5616
}
// res = str.substring(0,str.length()-4); // 455636460793
// res += "####"; //last four digits ####
/// return res; //45563640793####
}
public static void main(String[] args) {
System.out.println(CreditCardMask.Maskify("4556364607935616")); // should return "############5616"
System.out.println(CreditCardMask.Maskify("64607935616"));
System.out.println(CreditCardMask.Maskify("145785"));
System.out.println(CreditCardMask.Maskify("1 "));
System.out.println(CreditCardMask.Maskify(""));
}
}