Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- String ISBN;
- Scanner keyboard = new Scanner(System.in);
- while (0 == 0) {
- System.out.println("Geef een ISBN-nummer in om te controleren, of STOP om te stoppen.");
- ISBN = keyboard.next();
- if (ISBN.equals("STOP")) {
- // kheb de controle of t t woord stop is vanboven gezet
- // also, ge moest 'STOP' niet in stop steken, dat kan gwn in de functie zelf
- System.exit(0);
- } else if (ISBN.length() == 13 && ("978".equals(ISBN.substring(0, 3)) || "979".equals(ISBN.substring(0, 3)))) {
- int o = 0;
- int e = 0;
- // met een for-loop steek ik alle juiste waarden in o en e
- for (int i = 1; i < 13; i += 2) {
- o += Integer.parseInt(ISBN.substring(i - 1, i));
- e += Integer.parseInt(ISBN.substring(i, i + 1));
- }
- // ik reken uit wat x13 zou moeten zijn en kijk dan of dit hetzelfde is als de werkelijke x13
- int x13_actual = Integer.parseInt(ISBN.substring(12, 13));
- int x13_shouldbe = ((10 - ((o + 3 * e) + 10) % 10) + 10) % 10;
- System.out.println(x13_actual);
- System.out.println(x13_shouldbe);
- if (x13_actual == x13_shouldbe) {
- System.out.println("\"" + ISBN + "\"" + " is een geldig ISBN.");
- } else {
- System.out.println("\"" + ISBN + "\"" + " is een ongeldig ISBN.");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement