ADoyle4

Untitled

Feb 28th, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. class QuestionEight{
  2. static boolean isISBN(String s)
  3. {
  4. if(s.length()!=13)
  5. {
  6. return false;
  7. }
  8.  
  9. char c = s.charAt(12);
  10.  
  11. if(c!='x' && !Character.isDigit(c))
  12. {
  13. return false;
  14. }
  15. int numSeps =0;
  16. int numDigits=0;
  17.  
  18. for(int i =0;i<12; i++)
  19. {
  20. c=s.charAt(i);
  21. if(Character.isDigit(c))
  22. {
  23. numDigits++;
  24. }
  25. else if(c== ' ' || c== '-')
  26. {
  27. numSeps++;
  28. }
  29. }
  30. return numDigits==9 && numSeps==3;
  31. }
  32.  
  33. public static void main(String [] args){
  34.  
  35. System.out.println("please enter the ISBN: ");
  36. String isbn = Console.readString();
  37.  
  38. if(isISBN(isbn))
  39. {
  40. System.out.println("valid ISBN");
  41. }
  42. else
  43. {
  44. System.out.println("not valid");
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment