I must create an algorithm that calculates a value a high to an exponent b. It is an exercise that can not use Math.pow. I made the algorithm and when I put negative exponent the result buga.
public static void main(String[] args) {
Scanner ler = new Scanner(System.in);
int base, expoente, calculo=1;
System.out.println("Informe a base:");
base = ler.nextInt();
System.out.println("Informe o expoente:");
expoente = ler.nextInt();
while(expoente!=0) {
calculo=base*calculo;
expoente--;
}
System.out.println(calculo);
}
}
I know it's because of the while that is giving this error but I have no idea how to fix it.