Answered step by step
Verified Expert Solution
Link Copied!

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

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

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

Students also viewed these Databases questions

Question

How did you feel about taking piano lessons as a child? (general)

Answered: 1 week ago