Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. class ISBN {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. String ISBN = args[0];
  6. int summe = 0, rest = 0, zifferISBN = 0, pruefsumme = 0, pruefziffer = 0;
  7.  
  8. boolean ungerade = true, gueltigeISBN = true;
  9.  
  10. ISBN = ISBN.replace(" ", "").replace("-", "");
  11. System.out.println(ISBN);
  12.  
  13. for (int i = 0; i < 12; i++) {
  14. zifferISBN = ISBN.charAt(i) - 48;
  15.  
  16. if(ungerade) {
  17. summe = summe + zifferISBN;
  18. }
  19. else {
  20. summe = summe + (zifferISBN * 3);
  21. }
  22. ungerade = !ungerade;
  23. }
  24. pruefziffer = summe % 10;
  25.  
  26. // for (int i = 0; i < ISBN.length(); i++)
  27. // {
  28. // System.out.print(ISBN.charAt(i));
  29. // if (i == 2 || i == 3 || i == 7)
  30. // {
  31. // System.out.print("-");
  32. // }
  33. // }
  34.  
  35. // System.out.println("");
  36.  
  37. if (ISBN.length() == 13)
  38. {
  39. // ISBN wurde angegeben
  40. if (ISBN.charAt(12) - 48 == summe)
  41. {
  42. System.out.println("Pruefziffer war richtig, ihr wert is: " + pruefziffer);
  43. }
  44. else
  45. {
  46. System.out.println("Pruefziffer ist falsh, die richtige ist: " + pruefziffer);
  47. }
  48. }
  49. else // keine pruefziffer angegeben
  50. {
  51. System.out.println("Pruefziffer wurde nicht angegeben. Preufziffer ist: " + pruefziffer);
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement