Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3.  
  4. public class ISBN {
  5.  
  6.     /**
  7.      * @param args
  8.      */
  9.     public static void main(String[] args) {
  10.         // TODO Auto-generated method stub
  11.        
  12.         ISBN isbn = new ISBN();
  13.         System.out.println(isbn.pruefen("3-528-56508-X"));     
  14.     }
  15.    
  16.     static boolean pruefen(String isbn){
  17.        
  18.         int produkt = 0;
  19.        
  20.         String isbnOhneStrich = isbn.replace("-", "");
  21.         if(isbnOhneStrich.length() != 10){
  22.             throw new IllegalArgumentException();
  23.         }
  24.        
  25.         int i = 0;
  26.         int x;
  27.         for(i=0,x = 10;i<isbnOhneStrich.length();i++,x--)
  28.         {
  29.             if(isbnOhneStrich.charAt(i)== 'X'){
  30.                 produkt += (10*x);
  31.             }else{
  32.             int bla = Integer.parseInt(""+isbnOhneStrich.charAt(i)) * x;
  33.             produkt+=bla;
  34.             }
  35.         }
  36.        
  37.         boolean match = false;
  38.         if(produkt%11 == 0){
  39.             match=true;
  40.         }
  41.        
  42.         return match;
  43.     }
  44.    
  45.  
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement