Created
August 22, 2016 07:01
-
-
Save omidp/f0e5c68e5c186b0d240d6ecedb1b9771 to your computer and use it in GitHub Desktop.
تولید کننده کد ملی در جاوا
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GenerateIranNationalCode | |
{ | |
public static void main(String[] args) | |
{ | |
List<Integer> numbers = new ArrayList<Integer>(); | |
StringBuilder sb = new StringBuilder(); | |
for (int i = 0; i < 9; i++) | |
{ | |
int nextInt = ThreadLocalRandom.current().nextInt(0, 9 + 1); | |
numbers.add(nextInt); | |
sb.append(nextInt); | |
} | |
int i = 10; | |
int tempB = 0; | |
for (Integer integer : numbers) | |
{ | |
tempB += integer * i; | |
i--; | |
} | |
int tempC = tempB - (tempB / 11) * 11; | |
if (tempC == 0) | |
{ | |
// apend tempc | |
sb.append(tempC); | |
} | |
if (tempC == 1) | |
{ | |
// append 1 | |
sb.append(tempC); | |
} | |
if (tempC > 1) | |
{ | |
// append tempc -11 | |
sb.append(Math.abs(tempC - 11)); | |
} | |
System.out.println(sb.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment