Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1.  
  2. public class NumberCheck {
  3. public static void main(String[] args) {
  4. System.out.print(check("8642"));
  5. }
  6.  
  7. public static boolean check(String number) {
  8. String newnum = "";
  9. for (int i = 0; i < number.length(); i++) {
  10. int a = Character.getNumericValue(number.charAt(number.length() - 1 - i));
  11. if (i % 2 != 0) {
  12. a = 2 * a;
  13. if (a > 10) {
  14. a = (a % 10) + 1;
  15. }
  16. }
  17. newnum = "" + a;
  18. }
  19. int sum = 0;
  20. for (int i = 0; i < newnum.length(); i++) {
  21. sum = sum + Character.getNumericValue(newnum.charAt(i));
  22.  
  23. }
  24. if (sum % 10 == 0) {
  25. return true;
  26. } else {
  27. return false;
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement