THINK FIRST·CODE LATER

← All labs

The check digit of an ISBN-10

Problem

An ISBN-10 book number has nine digits d1…d9 followed by a check digit:

check = (d1×1 + d2×2 + d3×3 + … + d9×9) % 11

If the result is 10, the check digit is written X. Isbn10 reads the first nine digits as one int (so leading zeros are lost: 013601267 is read as 13601267), extracts the nine digits with / and %, and prints the check digit and the full ISBN — with its leading zeros.

For the input

013601267

the program prints

Check digit: 1
The ISBN-10 number is 0136012671

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

l6-8-data-1.txt

013601267
What your program must print for l6-8-data-1.txt
Check digit: 1
The ISBN-10 number is 0136012671

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < l6-8-data-1.txt

Windows PowerShell does not understand <:

Get-Content l6-8-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.