소감

소스

~cpp SocialNumber.java

~cpp 
import java.util.Scanner;

public class SocialNumber 
{
	private String num;

	public void input()
	{
		Scanner input = new Scanner(System.in);
		num = input.next();
	}
	
	public boolean validate()
	{
		int validateNum[] = {2,3,4,5,6,7,8,9,2,3,4,5}; 
		int sum = 0;
		int key = (int)num.charAt(12) - 48;
		for (int i = 0; i < 12; i++)
			sum += ((int)num.charAt(i) - 48) * validateNum[i];
		sum = 11 - (sum %11);
		if (sum >= 10)
			sum %= 10;
		if (key == sum)
			return true;
		return false;
	}
}

~cpp TestSocialNuber.java

~cpp 
public class TestSocialNumber 
{
	public static void main(String[] args) 
	{
		SocialNumber socialNum = new SocialNumber();
		socialNum.input();
		boolean isRight = socialNum.validate();
		if (isRight == true)
			System.out.println("대한민국 국민이네요~ ^^ 안녕하세요!");
		else
			System.out.println("혹시 간첩???? -_-;;");
	}

}

나한테 할말

Retrieved from http://wiki.zeropage.org/wiki.php/주민등록번호확인하기/문보창
last modified 2021-02-07 05:31:08