Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. String ISBN;
  7.  
  8. Scanner keyboard = new Scanner(System.in);
  9.  
  10. while (0 == 0) {
  11.  
  12. System.out.println("Geef een ISBN-nummer in om te controleren, of STOP om te stoppen.");
  13. ISBN = keyboard.next();
  14.  
  15. if (ISBN.equals("STOP")) {
  16. // kheb de controle of t t woord stop is vanboven gezet
  17. // also, ge moest 'STOP' niet in stop steken, dat kan gwn in de functie zelf
  18. System.exit(0);
  19. } else if (ISBN.length() == 13 && ("978".equals(ISBN.substring(0, 3)) || "979".equals(ISBN.substring(0, 3)))) {
  20.  
  21. int o = 0;
  22. int e = 0;
  23. // met een for-loop steek ik alle juiste waarden in o en e
  24. for (int i = 1; i < 13; i += 2) {
  25. o += Integer.parseInt(ISBN.substring(i - 1, i));
  26. e += Integer.parseInt(ISBN.substring(i, i + 1));
  27. }
  28. // ik reken uit wat x13 zou moeten zijn en kijk dan of dit hetzelfde is als de werkelijke x13
  29. int x13_actual = Integer.parseInt(ISBN.substring(12, 13));
  30. int x13_shouldbe = ((10 - ((o + 3 * e) + 10) % 10) + 10) % 10;
  31. System.out.println(x13_actual);
  32. System.out.println(x13_shouldbe);
  33. if (x13_actual == x13_shouldbe) {
  34. System.out.println("\"" + ISBN + "\"" + " is een geldig ISBN.");
  35. } else {
  36. System.out.println("\"" + ISBN + "\"" + " is een ongeldig ISBN.");
  37. }
  38. }
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement