MY mENU


Wednesday 23 January 2013

A MobileNumber is a VIP number if it satisfy the following conditions.


  1. The operator should be Vodafone.
  2. Atleast one 0 (Zero) should be exist in mobile number.
  3. The number should not end with 8.
  4. The single digit sum of all the digits in the number should be equal to 9. For example if the number is 9876543210, the sum is 9+8+7+...+1+0 = 45. Sum of 4+5 = 9.
Write a method: 
private boolean isVIPMobileNumber(String mobileNum, String operator)
mobileNum     phone number
operator

  
mobile operator as bsnl, Vodafone

import java.io.*;
import java.lang.*;
class Phno
{
String mobileNum;
String operator;
int count=0;
long sum=0;
long total_value=0;
 long value;
 long rem;
 long rem1;

private boolean isVIPMobileNumber(String mobileNum, String operator)
{
   this.mobileNum=mobileNum;
   this.operator=operator; 
  

   int len=mobileNum.length();
if(operator!="vadafone")
{
System.out.println("network is not vadafone");
    }

//System.out.println(len);
for(int i=0;i
{
   if(mobileNum.charAt(i)=='0')
{
count=count+1;
}
}
if(count>0)
{
}
else
{
System.out.println("at least one zero not avaliablee");
}

if(mobileNum.charAt(len-1)=='8'){
System.out.println("mobile number should not end with 8");
  }
value=Long.parseLong(mobileNum);

while(value!=0)
{
rem=value%10;
value=value/10;
sum=sum+rem;
}
//System.out.println(sum);
while(sum!=0)
{
    rem1=sum%10;
sum=sum/10;
total_value=total_value+rem1;
        }
if(total_value!=9)
{
System.out.println("sum of individual no's not equal to 9");
}
//System.out.println(total_value);
  
 System.out.println("VIP number");
 
return true;


}

public static void main(String[] args) 
{
String mno="9885603834";
String network="vadafone";
Phno pn=new Phno();
pn.isVIPMobileNumber(mno,network);

}
}

No comments:

Post a Comment