Giter Club home page Giter Club logo

samething's People

Watchers

James Cloos avatar

samething's Issues

マイナンバーシグマコード

import java.io.IOException;
import java.util.regex.Pattern;

public class Main {

/**
 * 11,12桁半角数字
 */
private static final String CHECK_REGEX = "[0-9]{11,12}";


public static void main( String[] args ) throws IOException {

    int c;
    StringBuilder input = new StringBuilder();
    while ( ( c = System.in.read() ) != -1 ) {

        if ( c == 10 ) {

            checkMyNmber( input.toString() );
            input = new StringBuilder();
            continue;
        }

        input.append( (char) c );

    }

}


private static void checkMyNmber( String myNmber ) {

    if ( !Pattern.matches( CHECK_REGEX, myNmber ) ) {
        System.out.println( "Error" );
        return;
    }

    String checkDigit = calcDigit( myNmber.substring( 0, 11 ) );

    if ( myNmber.length() == 11 ) {
        System.out.println( checkDigit );
    } else {
        if ( checkDigit.equals( myNmber.substring( 11, 12 ) ) ) {
            System.out.println( "OK" );
        } else {
            System.out.println( "NG" );
        }

    }
}


private static String calcDigit( String number ) {

    int sum = 0;
    for ( int i = 1; i <= 11; i++ ) {

        int pn = Integer.valueOf( number.substring( 11 - i, 12 - i ) );
        int qn = i <= 6 ? i + 1 : i - 5;
        sum += pn * qn;
    }

    int mod = sum % 11;

    if ( mod <= 1 ) {
        return "0";
    } else {
        return String.valueOf( 11 - mod );

    }

}

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.