-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathISBN.java
More file actions
66 lines (62 loc) · 1.33 KB
/
Copy pathISBN.java
File metadata and controls
66 lines (62 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.io.*;
public class ISBN
{
String s,s1;
int sum,a;
ISBN()
{ sum=0;
s=s1="";
a=0;
}
public void input()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the ISBN number");
s=br.readLine();
if(s.length()!=10)
{
System.out.println("INVALID INPUT");
System.exit(0);
}
if(s.charAt(s.length()-1)=='X')
{
for(int i=0;i<s.length()-1;i++)
s1+=s.charAt(i);
s1+="10";
}
else
{
s1=s;
}
a=Integer.parseInt(s1);
}
void display()
{
int i=1;
if(s1.length()==11)
{
sum+=a%100;
a=a/100;
i=2;
}
while(a>0)
{
sum+=((a%10)*i);
a=a/10;
i++;
}
if(sum%11!=0)
System.out.println("LEAVES REMAINDER – INVALID ISBN CODE");
else
{
System.out.println("Sum="+sum);
System.out.println("LEAVES NO REMAINDER – VALID ISBN CODE");
}
}
public static void main()throws IOException
{
ISBN ob=new ISBN();
ob.input();
ob.display();
}
}