java - How to break a long integer into mobile phone number? -
i had type code print output of number mobile phone format...
but shows error related method using in code ... please remove error ... , if alternative methods please mention .. here code
public class printaddressformat { public static void main(string[] args) { string name,address; long phonenum; scanner in = new scanner(system.in); system.out.println("enter name : "); name=in.nextline(); system.out.print("enter address : \n"); address=in.nextline(); system.out.print("enter phone number : \n"); phonenum=in.nextlong(); system.out.println("**********************************************"); system.out.println("name : "+name); system.out.println("address : "+address); system.out.println("phone number : "+ phoneformat(phonenum)); system.out.println("**********************************************"); void phoneformat(long temp) { long rem1=temp%10000; temp=temp/10000; long rem2=temp%100; temp=temp/100; system.out.println(temp+"-"+rem2+"-"+rem1); } } }
you can use maskformatter this. see code below
string phonemask= "###-###-####"; string phonenumber= "1234567890"; maskformatter maskformatter= new maskformatter(phonemask); maskformatter.setvaluecontainsliteralcharacters(false); maskformatter.valuetostring(phonenumber) ; system.out.println(maskformatter.valuetostring(phonenumber));
Comments
Post a Comment