HALLAR LA POTENCIA POR SUMAS

Clase Principal

package Pckpoten;
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 res,a,b;
        System.out.println("Ingrese la base");
        a=Integer.parseInt(Teclado.readLine());
        System.out.println("Ingrese el exponente");
        b=Integer.parseInt(Teclado.readLine());
        Potencia Obj= new Potencia(a,b);
        res=Obj.Elevar();
        System.out.println("El resultado es: "+res);
       
       
    }
}

Clase Potencia

package Pckpoten;

public class Potencia {
    private int b;//base
    private int e;//exponente

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

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentarios:

Publicar un comentario