Langdon Algar

Greenhorn
+ Follow
since Nov 27, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Langdon Algar

Macca,
Hi there, I am fairly new to Java as well, a way to do your
problem while using "int"s provided by the user and the "Math.pow" method
which takes "double"s would be to convert the ints to doubles and then send
them to the Math.pow method. As in the following:
-----------------------------------------------------------------
public class Powers {
public static void main(String[] args) {
if (args.length <2) {
System.out.println("enter two numbers on the command line");
} else {
int number1 = Integer.parseInt(args[0]);
int power1 = Integer.parseInt(args[1]);
int answer2;
double answer1;
double number2 = (double) number1;
double power2 = (double) power1;
answer1 = Math.pow(number2, power2);
answer2 = (int) answer1;

System.out.println(number1 + " to the " + power1 + " power is: " + answer2);
}
}
}
----------------------------------------------
Hope this helps,
Langdon
20 years ago