Friday, February 10, 2017

Write a java program to all valid IMEI no(15 digit) between 999999999990000 to 999999999999999.

import java.util.Scanner;
import static java.lang.System.out;
class Imei3
{
public static int sumDigit(int d)
{
int s=0;
while(d!=0)
{
s=s+(d%10);
d/=10;
}
return s;
}
static public void main(String...alt)
{
long a=999999999990000l,b=999999999999999l;
for(long j=a;j<=b;j++)
{
long n=j;
String s=Long.toString(n);
int l=s.length(),sum=0;
if(l!=15)
out.println(n+" is wrong input for IMEI");
else
{
int d=0,rem=0;
for(int i=15;i>=1;i--)
{
rem=(int)(n%10);
if(i%2==0)
rem=2*rem;
sum=sum+sumDigit(rem);  // if rem has 2 digit of value like(14) call sumDigit()
n/=10;
}
if(sum%10==0)
out.println(s);
}
}
}
}

Share this

0 Comment to "Write a java program to all valid IMEI no(15 digit) between 999999999990000 to 999999999999999."

Post a Comment