Showing posts with label check-valid-imei. Show all posts
Showing posts with label check-valid-imei. Show all posts

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);
}
}
}
}

Write a program in Java to input the first 14 digits of an IMEI number and find the (check)last digit of it.


The IMEI  has 14 digits plus a check digit) includes information on the origin, model, and serial number
of the device. The check digit (x) is obtained by computing the sum of digits then multiply that sum
with 9. And do modulo by 10. The modulo result will be the last(check) digit.

Write a program in Java to input the first 14 digits of an IMEI number and find the (check)last digit of it.

Ex:- IMEI No  49015420323751x
Step 1 :- Compute the sum of the digits according to the rule of IMEI Addition(52 in this case).
Step 2 :- Multiply the sum by 9 (9*52 = 468).
Step 3 :- Divide the result by 10 and note down the remainder (468 % 10)
Step 4 :- The last digit, 8, is the check digit.
 */

import static java.lang.System.out;
import java.io.Console;
class Imei2
{
static public int sumDigit(int rem)
{
int s=0;
while(rem!=0)
{
s=s+rem%10;
rem/=10;
}
return s;
}
public static void main(String...alt)
{
Console c=System.console();
String s=c.readLine("Enter 14 digit of IMEI Number : ");
long n=Long.parseLong(s);
if(s.length()!=14)
out.println("Wrong Imei inserted ");
else
{
int sum=0,rem=0;
for(int i=14;i>=1;i--)
{
rem=(int)(n%10);
if(i%2==0)
rem=2*rem;
sum=sum+sumDigit(rem);
n/=10;
}
out.println("Sum of IMEI = "+sum);
int ld=(sum*9)%10; //Finding Last digit
out.println("Last digit of "+s+" = "+ld);
}
}
}

Write a java program to input an IMEI no(15 digit) and check whether it is a valid IMEI no or not.

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.
Write a java program to input an IMEI no(15 digit) and check whether it is a valid IMEI no or not.

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.");
}
}
}