Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Class poweris

1/1

/**
* PROGRAM TO FIND A NUMBER RAISED TO A GIVEN POWER
*/
import java.io.*;
public class poweris
{
int n;
int m;
double p;
DataInputStream d=new DataInputStream(System.in);
poweris()
{
n=0;
m=0;
p=0.0;
}
double power(int n,int m)
{
if(m==0||n==1)
{
return 1;
}
if(m>-1)
{
return (n*power(n,m-1));
}
return (power(n,m+1)/n);
}
void findresult()throws IOException
{
System.out.println("ENTER NUMBER");
n=Integer.parseInt(d.readLine());
System.out.println("ENTER POWER");
m=Integer.parseInt(d.readLine());
p=power(n,m);
}
void printresult()throws IOException
{
System.out.println(n+" raised to "+m+" is "+p);
}
void main()throws IOException
{
poweris obj=new poweris();
obj.findresult();
obj.printresult();
}
}

Jan 16, 2015 11:24:51 PM

poweris1.main();
ENTER NUMBER
5
ENTER POWER
3
5 raised to 3 is 125.0
poweris1.main();
ENTER NUMBER
6
ENTER POWER
2
6 raised to 2 is 36.0

You might also like