If the modulo 10 of the summation of all the digits is 1


First your program should ask if the credit card is MasterCard or visa card. Then ask the 16 digit credit card number. Then add all the digits in the credit card number and get the modulo 10. If the modulo 10 of the summation of all the digits is zero, then its valid visa card.

If the modulo 10 of the summation of all the digits is 1 then its valid MasterCard. Otherwise, the number customer has entered is an invalid card number. There are two other requirements that make this problem unique:

A) You need to read the card number as a single string and each 4 numbers in the card must be separated by a space. For example, following is a correct input 1234 5678 6789 1235

B) Card number must have 16 digits. If not, display the error message "incorrect card number"

My main issue has been parsing the integers from the long string. I'm using scan.nextLine() to capture the entire number with the spaces, but when I try to parse it, I get a NumberFormatException error.

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: If the modulo 10 of the summation of all the digits is 1
Reference No:- TGS01691923

Now Priced at $20 (50% Discount)

Recommended (91%)

Rated (4.3/5)