-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split a number into different section
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*Books are identified by International Standard Book Number(ISBN). ISBNs contain | ||
13 digits, arranged in five groups such as 978-0-13-110362-8. The first group | ||
(GSI prefix) is currently either 978 or 979. The group identifier specifies the | ||
language or country of origin (for example 0 and 1 are used for English speaking | ||
countries). The publisher code identifies the publisher (13 is the code for | ||
Prentice Hall, New Jersey). The item number is assigned by the publisher to | ||
identify a specific book (110362 is the code for the book "The C Programming | ||
Language" by Kernighan and Ritchie) and ISBN ends with a check digit that's used | ||
to verify the accuracy of preceding digits. Write a program that breaks down the | ||
ISBN entered by the user.: | ||
Sample Input: | ||
----------------------- | ||
Enter ISBN: 978-0-13-110362-8 | ||
Sample Output: | ||
----------------------- | ||
GSI Prefix: 978 | ||
Group Identifier: 0 | ||
Publisher Code: 13 | ||
Item Number: 110362 | ||
Check Digit: 8 | ||
Note: The number of digits in each group may vary. You can't assume that the | ||
groups have the length shown in the sample output. You can test your program | ||
with actual ISBN values (usually found on the back cover of a book and on the | ||
copyright page */ | ||
|
||
import java.util.*; | ||
public class Split { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
System.out.println("Enter ISBN: "); | ||
String n = sc.nextLine(); | ||
String[] data = ExtractElement(n); | ||
if(data!=null) | ||
{ | ||
int i=0; | ||
System.out.println("GSI Prefix: "+data[i++]); | ||
System.out.println("Group Identifier: "+data[i++]); | ||
System.out.println("Publisher Code: "+data[i++]); | ||
System.out.println("Item Number: "+data[i++]); | ||
System.out.println("Check Digit: "+data[i++]); | ||
} | ||
} | ||
public static String[] ExtractElement(String data) | ||
{ | ||
String[] num = data.split("-"); | ||
if(num.length==5) | ||
{ | ||
return num; | ||
} | ||
return null; | ||
} | ||
} |