Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ISBN {
- public static void main(String[] args) {
- String ISBN = args[0];
- int summe = 0, rest = 0, zifferISBN = 0, pruefsumme = 0, pruefziffer = 0;
- boolean ungerade = true, gueltigeISBN = true;
- ISBN = ISBN.replace(" ", "").replace("-", "");
- System.out.println(ISBN);
- for (int i = 0; i < 12; i++) {
- zifferISBN = ISBN.charAt(i) - 48;
- if(ungerade) {
- summe = summe + zifferISBN;
- }
- else {
- summe = summe + (zifferISBN * 3);
- }
- ungerade = !ungerade;
- }
- pruefziffer = summe % 10;
- // for (int i = 0; i < ISBN.length(); i++)
- // {
- // System.out.print(ISBN.charAt(i));
- // if (i == 2 || i == 3 || i == 7)
- // {
- // System.out.print("-");
- // }
- // }
- // System.out.println("");
- if (ISBN.length() == 13)
- {
- // ISBN wurde angegeben
- if (ISBN.charAt(12) - 48 == summe)
- {
- System.out.println("Pruefziffer war richtig, ihr wert is: " + pruefziffer);
- }
- else
- {
- System.out.println("Pruefziffer ist falsh, die richtige ist: " + pruefziffer);
- }
- }
- else // keine pruefziffer angegeben
- {
- System.out.println("Pruefziffer wurde nicht angegeben. Preufziffer ist: " + pruefziffer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement