Power of 10 in java


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Power of 10 in java

  1. #1
    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. #2
    Join Date
    Feb 2004
    Posts
    541
    Math.pow(a,b) will compute a^b

  3. #3
    Join Date
    Oct 2004
    Posts
    18
    Thanks for the answer above.

    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. #4
    Join Date
    Feb 2004
    Posts
    541
    Do you want the swapping to follow any particular rules?

  5. #5
    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. #6
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    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));
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center