Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Check digit . program CheckDigit.java that takes a 12 or 13-digit long as a command-line argument and displays the digit computed as follows: Please leave

  1. Check digit . program CheckDigit.java that takes a 12 or 13-digit long as a command-line argument and displays the digit computed as follows: Please leave step by step comments for me to understand what your doing each steps.
    • Take for an example the number 048231312622
    • Sum every other digit of the code, starting from the right. In the example, that is 2+6+1+1+2+4=16. Discard the tens digit and keep the ones digit, 6.
    • Start with the second to last digit and do the same thing. Sum the digits, discard the tens digit and keep the ones digit. In this example this is 2+2+3+3+8+0=18. Discarding the 10 leaves 8. Multiply this number by 3 and again discard the tens digit. 83=24, leaving 4.
    • Add the numbers from steps 1 and 2. Again drop the tens digit. 6+4=10, leaving the digit 0 (zero).
    • Hint 1: the maximum value that can be stored in an integer variable is 2147483647 which is only 10 digits long. To read a 12 or 13-digit integer from command line argument you will need to store it in a long variable. Use: long number = Long.parseLong(args[0]); to read a long from the command line.
    • Hint 2: to extract the rightmost digit of a number use the modulus operator.
    • Hint 3: to remove the rightmost digit of a number use the integer division by 10
    • Hint 4: for full credit use a loop to compute the sums
  • Assume the input value used to test your program is a 12 or 13-digit positive integer.

java CheckDigit048231312622 0

java CheckDigit9780470454310 8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Contrast the hierarchical and decentralized methods of control.

Answered: 1 week ago

Question

Regulation of normal activities of the human heart take place?

Answered: 1 week ago

Question

The location of the neuro centre activity of the heart is.......?

Answered: 1 week ago