Credit Card Number Check. The last digit of a credit card number is the check digit,...

80.2K

Verified Solution

Question

Programming

Credit Card Number Check. The last digit of a credit card numberis the check digit, which protects against transcription errorssuch as an error in a single digit or switching two digits. Thefollowing method is used to verify actual credit card numbers but,for simplicity, we will describe it for numbers with 8 digitsinstead of 16:

• Starting from the rightmost digit, form the sum of every otherdigit. For example, if the credit card number is 4358 9795, thenyou form the sum 5 + 7 + 8 + 3 = 23.

• Double each of the digits that were not included in thepreceding step. Add all digits of the resulting numbers. Forexample, with the number given above, doubling the digits, startingwith the next-to-last one, yields 18 18 10 8. Adding all digits inthese values yields 1 + 8 + 1 + 8 + 1 + 0 + 8 = 27.

• Add the sums of the two preceding steps. If the last digit ofthe result is 0, the number is valid. In our case, 23 + 27 = 50, sothe number is valid. Write a program in Java that implements thisalgorithm. The user should supply an 8-digit number, and you shouldprint out whether the number is valid or not. If it is not valid,you should print the value of the check digit that would make itvalid.

Answer & Explanation Solved by verified expert
4.3 Ratings (802 Votes)
Hi thereI have solved the question according to the steps describedaboveThe Codeimport javautilpublic class creditCard public static void mainString args int numlength0 Scanner sc new ScannerSystemin loop till we get    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students