Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newb...Variable Exponents

Status
Not open for further replies.

iXPhound

Technical User
Feb 25, 2001
146
US
Hi All;

Have what I hope is an easy question that is driving me insane. I hope this isn't terribly stupid as I am new to Java. I have an int digitCount and this is what I am trying to do. Simply...

System.out.println(10^(digitCount)); ... and is ^ even to the power of? When I try the same line replacing (digitCount) with 2, the result I get is 8 :( ?

The result I am trying to get is 10 to the power of the value of digitCount. Is there a way to do this without using a recursive method?

TIA!!!!
 
The "^" is actually the logical exclusive or. You are going to have to brute force this, but you won't have to do it recursively. Everything that can be done recursevely can be done with loops, and this one would be rather simple to do with a for loop.

To start you off...
Code:
for(int i = 0; i < digitCount; i++)
{
  // ...
}

-Bones
 
What's wrong with the Math.pow(double a, double b) method?
Code:
System.out.println( Math.pow(10, digitCount) );

Tim
 
thanks very much guys....the help is much appreciated!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top