private static String toPrettyString(long creditCardNumber){
  String plain=Long.toString(creditCardNumber);
  int length=plain.length();
switch (length) {
case 12:
    return plain.substring(0,3) + ' ' + plain.substring(3,6)+ ' '+ plain.substring(6,9)+ ' '+ plain.substring(9,12);
case 13:
  return plain.substring(0,4) + ' ' + plain.substring(4,7)+ ' '+ plain.substring(7,10)+ ' '+ plain.substring(10,13);
case 14:
return plain.substring(0,2) + ' ' + plain.substring(2,6)+ ' '+ plain.substring(6,10)+ ' '+ plain.substring(10,14);
case 15:
return plain.substring(0,3) + ' ' + plain.substring(3,7)+ ' '+ plain.substring(7,11)+ ' '+ plain.substring(11,15);
case 16:
return plain.substring(0,4) + ' ' + plain.substring(4,8)+ ' '+ plain.substring(8,12)+ ' '+ plain.substring(12,16);
case 17:
return plain.substring(0,1) + ' ' + plain.substring(1,5)+ ' '+ plain.substring(5,9)+ ' '+ plain.substring(9,13)+ ' '+ plain.substring(13,17);
default :
return plain;
}
}

private static String toPrettyString ( long creditCardNumber ) { String plain = Long . toString ( creditCardNumber ) ; int length = plain . length ( ) ; switch ( length ) { case 12 : return plain . substring ( 0 , 3 ) + ' ' + plain . substring ( 3 , 6 ) + ' ' + plain . substring ( 6 , 9 ) + ' ' + plain . substring ( 9 , 12 ) ; case 13 : return plain . substring ( 0 , 4 ) + ' ' + plain . substring ( 4 , 7 ) + ' ' + plain . substring ( 7 , 10 ) + ' ' + plain . substring ( 10 , 13 ) ; case 14 : return plain . substring ( 0 , 2 ) + ' ' + plain . substring ( 2 , 6 ) + ' ' + plain . substring ( 6 , 10 ) + ' ' + plain . substring ( 10 , 14 ) ; case 15 : return plain . substring ( 0 , 3 ) + ' ' + plain . substring ( 3 , 7 ) + ' ' + plain . substring ( 7 , 11 ) + ' ' + plain . substring ( 11 , 15 ) ; case 16 : return plain . substring ( 0 , 4 ) + ' ' + plain . substring ( 4 , 8 ) + ' ' + plain . substring ( 8 , 12 ) + ' ' + plain . substring ( 12 , 16 ) ; case 17 : return plain . substring ( 0 , 1 ) + ' ' + plain . substring ( 1 , 5 ) + ' ' + plain . substring ( 5 , 9 ) + ' ' + plain . substring ( 9 , 13 ) + ' ' + plain . substring ( 13 , 17 ) ; default : return plain ; } }
convert a creditcardnumber as long to a formatted string . currently it breaks 16 - digit numbers into groups of 4 .
