fork download
  1. class validateIBAN{
  2.  
  3. private static int calcMod97(String D) {
  4. String N = D.substring(0, 9);
  5. int remainder;
  6. int end = D.length() - 1;
  7. int pos = 9;
  8. boolean last = false;
  9. while(true) {
  10. remainder = Integer.valueOf(N) % 97;
  11. if(!last) {
  12. if((pos + 7) < end) {
  13. N = String.valueOf(remainder).concat(D.substring(pos, pos + 7));
  14. pos = pos + 7;
  15. } else {
  16. N = String.valueOf(remainder).concat(D.substring(pos));
  17. pos = end;
  18. last = true;
  19. }
  20. } else {
  21. break;
  22. }
  23. }
  24. return remainder;
  25. }
  26. public static void main(String[] args) {
  27. String IBAN1 = "00120345030000067890142807";
  28. String IBAN2 = "20389433376000130761142872";
  29. System.out.println(IBAN1);
  30. System.out.println(calcMod97(IBAN1));
  31. System.out.println(IBAN2);
  32. System.out.println(calcMod97(IBAN2));
  33. }
  34. }
Success #stdin #stdout 0.06s 32476KB
stdin
Standard input is empty
stdout
00120345030000067890142807
1
20389433376000130761142872
1