Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NumberCheck {
- public static void main(String[] args) {
- System.out.print(check("8642"));
- }
- public static boolean check(String number) {
- String newnum = "";
- for (int i = 0; i < number.length(); i++) {
- int a = Character.getNumericValue(number.charAt(number.length() - 1 - i));
- if (i % 2 != 0) {
- a = 2 * a;
- if (a > 10) {
- a = (a % 10) + 1;
- }
- }
- newnum = "" + a;
- }
- int sum = 0;
- for (int i = 0; i < newnum.length(); i++) {
- sum = sum + Character.getNumericValue(newnum.charAt(i));
- }
- if (sum % 10 == 0) {
- return true;
- } else {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement