Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class ISBN {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- ISBN isbn = new ISBN();
- System.out.println(isbn.pruefen("3-528-56508-X"));
- }
- static boolean pruefen(String isbn){
- int produkt = 0;
- String isbnOhneStrich = isbn.replace("-", "");
- if(isbnOhneStrich.length() != 10){
- throw new IllegalArgumentException();
- }
- int i = 0;
- int x;
- for(i=0,x = 10;i<isbnOhneStrich.length();i++,x--)
- {
- if(isbnOhneStrich.charAt(i)== 'X'){
- produkt += (10*x);
- }else{
- int bla = Integer.parseInt(""+isbnOhneStrich.charAt(i)) * x;
- produkt+=bla;
- }
- }
- boolean match = false;
- if(produkt%11 == 0){
- match=true;
- }
- return match;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement