Java program to find n power of any number

• June 10th, 2009, 07:12 PM
Eldiablo
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.
• June 10th, 2009, 07:43 PM
Eldiablo
Re: Pleaseeeee help with this programmm!!!!
• June 10th, 2009, 09:33 PM
Truffy
Re: Pleaseeeee help with this programmm!!!!
wait for my code
• June 10th, 2009, 09:51 PM
Truffy
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);     }   }```
• June 10th, 2009, 11:32 PM
Eldiablo
Re: Pleaseeeee help with this programmm!!!!
Hey thanks a lot man. You saved my life.
• June 11th, 2009, 01:16 AM
Truffy
Re: Pleaseeeee help with this programmm!!!!
• June 11th, 2009, 02:28 AM
Eldiablo
Re: Pleaseeeee help with this programmm!!!!
Oh wow lol I'm so very sorry. Thanks again
• June 11th, 2009, 02:30 AM
Truffy
Re: Pleaseeeee help with this programmm!!!!
No problem with that. :)
• June 11th, 2009, 03:10 AM
JavaPF
Re: Pleaseeeee help with this programmm!!!!
Hello Eldiablo,

Welcome to the Java Programming Forums.

Good work Truffy. :D
• June 11th, 2009, 03:15 AM
Truffy
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