Danny Muñoz
Programa que eleva un numero a cualquier exponente que el usuario ingrese mediante sumas sucesivas.
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{
        // TODO code application logic here
        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;
    }   
}



CAPTURAS


1 Response

Publicar un comentario