domingo, 23 de octubre de 2011

POTENCIACION


Programa que  implemente una clase potencia por medio de suma.

CLASE CALCULO DE POTENCIACION

package poten;
public class Potencia {
private int z;
private int x;
public Potencia(int z, int z) {
this.b = z;
this.e = x;}
public int Elevar(){
int r=0,n=1;
for(int h=0;h<this.x;h++){
r=0;
for(int i=0;i<this.z;i++){
r+=n;}
n=r;}
return r;}}

CLASE PRINCIPAL

package poten;
import java.io.*;
public class Principal {
public static InputStreamReader Leer= new InputStreamReader(System.in);
public static BufferedReader Teclado= new BufferedReader(Leer);
public static void main(String[] args) throws IOException{
int resul,o,p;
System.out.println("Ingrese la base");
o=Integer.parseInt(Teclado.readLine());
System.out.println("Ingrese el exponente");
p=Integer.parseInt(Teclado.readLine());
Potencia Obj= new Potencia(o,p);
resul=Obj.Elevar();
System.out.println("El resultado es: "+resul);}}



No hay comentarios:

Publicar un comentario