DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: Power of 10 in java

1. Registered User
Join Date
Oct 2004
Posts
18

## Power of 10 in java

hi there,

I am looking a function that can do power of 10. Example: 10 to power of 0 is 1, 10 to the power of 1 is 10, 10 to the power of 2 is 100. etc.

2. Senior Member
Join Date
Feb 2004
Posts
541
Math.pow(a,b) will compute a^b

3. Registered User
Join Date
Oct 2004
Posts
18

I have one more question, I am looking the logic to solve the following question.

I have an array containing N digits of integer. I'd like to swapping those integer around. For example: 12345. becomes: 12354, 12534, 15234 and so on.

thanks!

4. Senior Member
Join Date
Feb 2004
Posts
541
Do you want the swapping to follow any particular rules?

5. Registered User
Join Date
Oct 2004
Posts
18
No.

Basically what I am trying to do is swap it and then compare to the orginal set to see if it is greater than. if not, keep swapping until it's greater than the orginal.

For example: 12345 to 12354. so 12354 is > then 12345.

6. The simplest way to shuffle digits is to convert the number to a byte array, then shuffle this array, and convert the shuffled byte array back to an int.
Code:
```    .
.
// convert int to byte array
byte [] bb=Integer.toString(newInt).getBytes();
// shuffle the bytes
.
.
// convert byte array to int
int newInt=Integer.parseInt(new String(b));```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise