3

I know it is a simple question and I know the way to do it, only need of mine here is Performance and with less time as possible it should do.

I am getting input as

long l = 149; 

I want to make this number of size 10 with additional numbers to be added at starting to make it of 10 digit. above number should get converted to,

 0000000149. 

Similarly,

1 -> 0000000001 13 -> 0000000013 888888 -> 0000888888 

1. I tried with loop, like checking number length, subtracting number length by 10, then adding number of zero as the subtraction result i got.

2 Already created array like

arr[0, 00, 000, 0000, 00000, 000000, 0000000, 00000000, 000000000, 0000000000]; 

here I am doing same thing, subtracting my number length with 10 and getting arr[numberLenth -10] + number

I am getting desired result.

I want to make sure to check is there any better solution to this like using bitwise operator for such requirement?

Thanks

5
  • 1
    See stackoverflow.com/questions/473282/… Commented Jul 30, 2013 at 7:39
  • 1
    Or may be this - stackoverflow.com/questions/4469717/… Commented Jul 30, 2013 at 7:40
  • See also stackoverflow.com/a/391978/44853 Commented Jul 30, 2013 at 7:40
  • in which way are you creating these formatting? If console, you can always just do System.out.format("%10d", numberVariable); Commented Jul 30, 2013 at 7:41
  • Thanks... i got answer on link pointed by @Tichodroma. Commented Jul 30, 2013 at 7:54

1 Answer 1

1

Do you like this?

String.format("%010d", 123); 
Sign up to request clarification or add additional context in comments.

2 Comments

"%10d" prints leading zeroes? Since when?
I got the answer, i need to do like String data = String.format("%010d", 1234);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.