QuestionQ61

Working with Selected Classes from the Java API

You are developing a banking module. You have created a class named ccMask that has a maskcc method.

Given this code fragment:

Question Image

You must ensure that the maskcc method returns a string that conceals every digit of the credit card number except its last four digits, while retaining the hyphens separating each group of four digits.

Which two code fragments can you use independently at line n1 to meet this requirement?

Question Image

Choose two
  • A Option A
  • B Option B
  • C Option C
  • D Option D
Explanation

Indexes 15 through 18 of 1234-5678-9101-1121 are the final four digits, 1121. substring(15, 19) returns that range because the end index is exclusive, and StringBuilder.append(creditCard, 15, 19) appends the same range to the mask. Both produce XXXX-XXXX-XXXX-1121.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!