Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class QuestionEight{
- static boolean isISBN(String s)
- {
- if(s.length()!=13)
- {
- return false;
- }
- char c = s.charAt(12);
- if(c!='x' && !Character.isDigit(c))
- {
- return false;
- }
- int numSeps =0;
- int numDigits=0;
- for(int i =0;i<12; i++)
- {
- c=s.charAt(i);
- if(Character.isDigit(c))
- {
- numDigits++;
- }
- else if(c== ' ' || c== '-')
- {
- numSeps++;
- }
- }
- return numDigits==9 && numSeps==3;
- }
- public static void main(String [] args){
- System.out.println("please enter the ISBN: ");
- String isbn = Console.readString();
- if(isISBN(isbn))
- {
- System.out.println("valid ISBN");
- }
- else
- {
- System.out.println("not valid");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment