TRY – CATCH
import javax.swing.JOptionPane;
public class Potencia {
public static void main(String[] args) {
int base=0;
int exp=0;
int result = 0;
int i=0;
result = 1;
String str = “”;
str=JOptionPane.showInputDialog (“Digite a base”);
try{
base = Integer.parseInt(str);
}catch (Exception e){
JOptionPane.showMessageDialog(null, “numero inválido”);
}
str=JOptionPane.showInputDialog (“Digite o expoente”);
try{
exp = Integer.parseInt(str);
}catch (Exception e){
JOptionPane.showMessageDialog(null, “numero inválido”);
}
do{
result = result * base;
i++;
}while(i<exp);
JOptionPane.showMessageDialog(null, result);
}
}
