Guest User

Untitled

a guest
Dec 7th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import java.io.*;
  2. class Prog1
  3. {
  4. BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  5. String str;
  6. int digit,c=1,x=0,i,len;
  7. char ch;
  8. public void show()throws Exception
  9. {
  10. System.out.println("Enter the ISBN code:");
  11. str=br.readLine();
  12. len=str.length();
  13. if(len!=10)
  14. {
  15. System.out.println("Invalid input.");
  16. return;
  17. }
  18. for(i=len-1;i>=0;i--)
  19. {
  20. ch=str.charAt(i);
  21. if(ch=='X')
  22. digit=10;
  23. else
  24. digit=ch-48;
  25. x=x+digit*c;
  26. c++;
  27. }
  28. System.out.println("nSum="+x);
  29. if(x%11==0)
  30. System.out.println("Leaves no remainder - valid ISBN code.");
  31. else
  32. System.out.println("Leaves remainder - invalid ISBN code.");
  33. }
  34. public static void main(String args[]) throws Exception
  35. {
  36. Prog1 ob=new Prog1();
  37. ob.show();
  38. }
  39. }
Add Comment
Please, Sign In to add comment