Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please fix my code so I can get this output: Enter the first 12-digit of an ISBN number as a string: 978013213080 The ISBN number
Please fix my code so I can get this output: Enter the first 12-digit of an ISBN number as a string: 978013213080 The ISBN number is 9780132130806 This was my output: import java.util.Scanner; public class Isbn { private static int getChecksum(String s) { // Calculate checksum int sum = 0; for (int i = 0; i < s.length(); i++) if (i % 2 == 0) sum += (s.charAt(i) - '0') * 3; else sum += s.charAt(i) - '0'; return 10 - sum; } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the first 12-digit of an ISBN number as a string: "); // get a string input String s = input.nextLine(); if (s.length()!= 12) { System.out.println(s + " is an invalid input"); System.exit(1); } int checksum = getChecksum(s); System.out.println("The ISBN number is " + s + (checksum == 10 ? "0" : checksum)); } } /*Enter the first 12-digit of an ISBN number as a string: 97801320 97801320 is an invalid input*/
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started