Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- class Prog1
- {
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- String str;
- int digit,c=1,x=0,i,len;
- char ch;
- public void show()throws Exception
- {
- System.out.println("Enter the ISBN code:");
- str=br.readLine();
- len=str.length();
- if(len!=10)
- {
- System.out.println("Invalid input.");
- return;
- }
- for(i=len-1;i>=0;i--)
- {
- ch=str.charAt(i);
- if(ch=='X')
- digit=10;
- else
- digit=ch-48;
- x=x+digit*c;
- c++;
- }
- System.out.println("nSum="+x);
- if(x%11==0)
- System.out.println("Leaves no remainder - valid ISBN code.");
- else
- System.out.println("Leaves remainder - invalid ISBN code.");
- }
- public static void main(String args[]) throws Exception
- {
- Prog1 ob=new Prog1();
- ob.show();
- }
- }
Add Comment
Please, Sign In to add comment