The International Mobile Station Equipment Identity(IMEI) is a number, usually unique, to identify
mobile phones, as well as some satellite phones. It is usually found printed inside the battery
compartment of the phone.
The IMEI (15 decimal digits: 14 digits plus a check digit) includes information on the origin, model
and serial number of the device.
The IMEI is validated in three steps:
Step1 :- Make double every alternate starting from 2nd digit (e.g., 7 becomes 14).
Step2 :- Sum of each digit even no. has two digits (e.g., 14 ? 1 + 4).
Step3 :- Check if the sum is fully divisible by 10.
Example:
If input is IMEI = 490154203237518
Step1 :- 9->18, 1->2, 4->8, 0->0, 2->4, 7->14, 1->2
Step2 :- 4+(1+8)+0+2+5+8+2+0+3+4+3+(1+4)+5+2+8=60
Since, 60 is divisible by 10, hence the given IMEI number is Valid. */
import java.util.Scanner;
import static java.lang.System.out;
class Imei
{
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)
{
out.print("Enter a 15 digit IMEI no. : ");
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
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+" is a valid IMEI No.");
else
out.println(s+" is an invalid IMEI No.");
}
}
}
mobile phones, as well as some satellite phones. It is usually found printed inside the battery
compartment of the phone.
The IMEI (15 decimal digits: 14 digits plus a check digit) includes information on the origin, model
and serial number of the device.
The IMEI is validated in three steps:
Step1 :- Make double every alternate starting from 2nd digit (e.g., 7 becomes 14).
Step2 :- Sum of each digit even no. has two digits (e.g., 14 ? 1 + 4).
Step3 :- Check if the sum is fully divisible by 10.
Example:
If input is IMEI = 490154203237518
Step1 :- 9->18, 1->2, 4->8, 0->0, 2->4, 7->14, 1->2
Step2 :- 4+(1+8)+0+2+5+8+2+0+3+4+3+(1+4)+5+2+8=60
Since, 60 is divisible by 10, hence the given IMEI number is Valid. */
import java.util.Scanner;
import static java.lang.System.out;
class Imei
{
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)
{
out.print("Enter a 15 digit IMEI no. : ");
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
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+" is a valid IMEI No.");
else
out.println(s+" is an invalid IMEI No.");
}
}
}
0 Comment to "Write a java program to input an IMEI no(15 digit) and check whether it is a valid IMEI no or not."
Post a Comment