Which two code fragments should you use at line n1, independently, to achieve this requirement?

You are developing a banking module. You have developed a class named ccMask that has a maskcc method.
Given the code fragment:

You must ensure that the maskcc method returns a string that hides all digits of the credit card number except the four last digits (and the hyphens that separate each group of four digits).
Which two code fragments should you use at line n1, independently, to achieve this requirement?

A. Option A
B. Option B
C. Option C
D. Option D

Download Printable PDF. VALID exam to help you PASS.

2 thoughts on “Which two code fragments should you use at line n1, independently, to achieve this requirement?

  1. B C
    public static String maskCC(String creditCard){
    String x =”xxxx-xxxx-xxxx-“;
    //c
    StringBuilder sb = new StringBuilder(x);
    sb.append(creditCard,15,19);
    return sb.toString();
    //B
    // return x + creditCard.substring(15,19);
    }
    public static void main(String[] args) {
    System.out.println(maskCC(“1234-5678-9101-1121”));
    }

  2. Answer B and C:

    The subString() method when applied to a StringBuilder object will return a String object. This is crucial point because the original StringBuilder object will not be manipulated. This is the reason why answer A is not correct.

    The append() method has many signatures, one of them takes a String and two offset arguments. This method signature allows us to append a specific section of the provided string to the required StringBuilder object. Thats why answer C is correct. We use toString() method in the return in order to print the contents of the string builder object instead of its memory address.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.