Skip to content

Instantly share code, notes, and snippets.

@omidp
Created August 22, 2016 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save omidp/f0e5c68e5c186b0d240d6ecedb1b9771 to your computer and use it in GitHub Desktop.
Save omidp/f0e5c68e5c186b0d240d6ecedb1b9771 to your computer and use it in GitHub Desktop.
تولید کننده کد ملی در جاوا
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