Java program to find n power of any number

Hey guys...I'm trying to make a java program that gets 2 numbers and the 2nd number is the exponent of the first. Example: the first number is 3 and the second number is 2. The value returned will be 3 to the 2 power, or 9. Please make use of if/else statements, while loops, for loops, arrays, and system.out.printlns. Thanks sooooooo much u guys. If u can't use the things I stated it's okay.

Re: Pleaseeeee help with this programmm!!!!

also when you write the code, please add comments to it to describe the process of each line

Re: Pleaseeeee help with this programmm!!!!

Re: Pleaseeeee help with this programmm!!!!

Hi Eldiablo,

Welcome to the forums.

Heres the sample code. Hope it gives you a hint and idea. :)

Code :

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ElDiablo {
private static BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args)throws IOException
{
String number1,exp;
double num1, n,num2, result = 0;
System.out.print("Enter a number : ");
number1=br.readLine();
num1=Double.parseDouble(number1);
System.out.print("Enter the second number : ");
exp=br.readLine();
num2=Double.parseDouble(exp);
n= Double.parseDouble(exp);
//you can add or play with this part. :) create your own logic in here so that you will not use the math //function
// for(double i=0; i<=num2; i++){
// result = num1 * num1;
// }
System.out.println("Using the Math fucntion" +Math.pow(num1, n));
// System.out.println("Not using the Math function : " +result);
}
}

Re: Pleaseeeee help with this programmm!!!!

Hey thanks a lot man. You saved my life.

Re: Pleaseeeee help with this programmm!!!!

Your welcome. Im a lady anyway. :D :o please mark as solved if you are satisfy with the answer. :)

Re: Pleaseeeee help with this programmm!!!!

Oh wow lol I'm so very sorry. Thanks again

Re: Pleaseeeee help with this programmm!!!!

Re: Pleaseeeee help with this programmm!!!!

Hello Eldiablo,

Welcome to the Java Programming Forums.

Good work Truffy. :D

Re: Pleaseeeee help with this programmm!!!!

Quote:

Originally Posted by

**JavaPF**
Hello Eldiablo,

Welcome to the Java Programming Forums.

Good work Truffy. :D

Thank you. :)

Cheers,

Truffy