1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
USPshnik [31]
2 years ago
9

ISBN-13 is a new standard for identifying books. It uses 13 digits d1d2d3d4d5d6d7d8d9d10d11d12d13. The last digit d13 is a check

sum, which is calculated from the other digits using the following formula: 10 - (d1 3d2 d3 3d4 d5 3d6 d7 3d8 d9 3d10 d11 3d12) % 10 If the checksum is 10, replace it with 0. Your program should read the input as a string.

Computers and Technology
1 answer:
qwelly [4]2 years ago
5 0

Answer:

// Scanner class is imported to allow program

// read input from user

import java.util.Scanner;

// Solution class is created

public class Solution {

// main method that begin program execution

public static void main(String[] strings) {

// Scanner object scan is created

// it receive input via the keyboard

Scanner scan = new Scanner(System.in);

// a prompt is displayed for user to enter 12 digits of ISBN

System.out.print("Enter the first 12 digits of an ISBN as string: ");

// user input is assigned to input

String input = scan.next();

//if length of input is not 12, program display error message and quit

if (input.length() != 12) {

System.out.println(input + " is Invalid input");

System.exit(0);

}

// 0 is assigned to checkSum

int checkSum = 0;

// for loop that goes through the string and does the computation

for (int i = 0; i < input.length(); i++) {

// if the index is even

if ((i + 1) % 2 == 0) {

checkSum += (input.charAt(i) - '0') * 3;

}

// if the index is odd

else

{

checkSum += input.charAt(i) - '0';

}

}

// modulo 10 of checkSum is assigned to checkSum

checkSum %= 10;

// checkSum is substracted from 10

checkSum = 10 - checkSum;

// if checkSum equals 10, 0 is concatenated with input

// else input is concatenated with checkSum

if (checkSum == 10) input += "0";

else input += checkSum;

// the new value of the isbn-13 is displayed

System.out.println("The ISBN-13 number is " + input);

}

}

Explanation:

The program is written in Java and well commented.

A sample of program output during execution is also attached.

You might be interested in
How many images are necessary for stereoscopy to work?
solong [7]

Answer:

2 images

Explanation:

The two images are then combined in the brain to give the perception of depth.

6 0
3 years ago
Easy ;) what is another word for ram
Anni [7]
Shoved or pushed :))))))))))
3 0
3 years ago
Read 2 more answers
Lawyers, accountants, and engineers are __________ resources of microsoft. (points : 2) informational non-revenue-producing mate
tester [92]
 <span>Lawyers, accountants, and engineers are human resources of Microsoft. </span>
7 0
2 years ago
Which of the following statements is true?
kompoz [17]
The answer to your question is A.
7 0
3 years ago
A number, a, is a power of b if it is divisible by b and a/b is a power of b. Write a function called is_power that takes parame
siniylev [52]

Answer:

Here is the Python program.

def is_power(a, b): # function that takes two positive integers a and b as arguments

  if a == b: #first base case: if both the numbers are equal

      return True #returns True if a=b

  elif b==1: #second base case: if the value of b is equal to 1

      return False #returns False if b==1

  else: #recursive step

      return a%b==0 and is_power(a/b, b) #call divisible method and is_power method recursively to determine if the number is the power of another          

Explanation:

return a%b==0 and is_power(a/b, b) statement basically means a number, a, is a power of b if it is divisible by b and a/b is a power of b

In the statement return a%b==0 and is_power(a/b, b) , a%b==0 checks whether a number a is completely divisible by number b. The % modulo operator is used to find the remainder of the division. If the remainder of the division is 0 it means that the number a is completely divisible by b otherwise it is not completely divisible.

The second part of the above statement calls is_power() method recursively. The and operator between the two means that both of the parts of the statement should be true in order to return true.

is_power() method takes two numbers a and b as arguments. First the method checks for two base cases. The first base case: a == b. Suppose the value of a = 1 and b =1 Then a is a  power of b if both of them are equal. So this returns True if both a and b are equal.

Now the program checks its second base case b == 1. Lets say a is 10 and b is 1 Then the function returns False because there is no positive integer that is the power of 1 except 1 itself.

Now the recursive case return return a%b==0 and is_power(a/b, b) takes the modulo of a and b, and is_power method is called recursively in this statement. For example if a is 27 and b is 3 then this statement:

a%b==0 is True because 27 is completely divisible by 3 i.e. 27 % 3 = 0

is_power(a/b,b) is called. This method will be called recursively until the base condition is reached. You can see it has two arguments a/b and b. a/b = 27/3 = 9 So this becomes is_power(9,3)

The base cases are checked. Now this else statement is again executed  return a%b==0 and is_power(a/b, b) as none of the above base cases is evaluated to true. when a%b==0 is True as 9 is completely divisible by 3 i.e. 9%3 =0 and is_power returns (9/3,3) which is (3,3). So this becomes is_power(3,3)

Now as value of a becomes 3 and value of b becomes 3. So the first base case a == b: condition now evaluates to true as 3=3. So it returns True.

Now in order to check the working of this function you can call this method as:                                                                                        

print(is_power(27, 3))

The output is:

True

5 0
3 years ago
Other questions:
  • Mary is proofreading an eBook. Sometimes she has to scroll several pages at a time. Which key on the numeric keypad will help he
    11·2 answers
  • 3. Write a method squareOfAsterisks that displays a solid square (the same number of rows and columns) of asterisks whose side i
    9·1 answer
  • What is the quick key to highlighting a column?
    14·1 answer
  • Jerry is making an address book using a digital database. He has a list of his immediate family and friends but wants to add a f
    9·2 answers
  • The desktops of computers running the same OS all look the same
    8·1 answer
  • These are statements given by witnesses under oath? A. Testimony B. Admissible Evidence C. Indirect Evidence D. Circumstantial E
    8·1 answer
  • Answer quick plzzz I only have 2 hours
    13·2 answers
  • When you first purchase a notebook, make sure you have a ____ CD containing the installed OS so you can recover from a failed ha
    5·1 answer
  • Rewrite the code below so that a transformation moves the div 100px to the right and 50px upward.
    5·1 answer
  • What is a simple definition for electricity?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!