Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String maskCardNumber(String clearcardnumber) throws Exception {

        if (clearcardnumber.length() < 10) {
            throw new Exception("Invalid number of digits");
        }

        int length = clearcardnumber.length();

        String prefix = clearcardnumber.substring(0, 4);
        String suffix = clearcardnumber.substring(length - 4);

        StringBuffer mask = new StringBuffer();
        mask.append(prefix).append("XXXXXXXXXX").append(suffix);

        return mask.toString();
    }
}