Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String makeCheckDegit(String s) {
        int odd = 0, even = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            int a = Integer.parseInt("" + c);
            if (i % 2 == 0) {
                odd += a;
            } else {
                even += a;
            }
        }
        int degit = 10 - ((even * 3 + odd) % 10);
        if (degit < 0 || degit >= 10) {
            degit = 0;
        }
        return String.valueOf(degit);
    }
}