Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package potenz;
- import javax.swing.JOptionPane;
- public class potenz {
- public static int berechnePotenz(int basis, int potenz){
- int ergebnis2 = basis;
- for (int i = 1; potenz > i; potenz = potenz - 1) {
- ergebnis2 = ergebnis2 * basis;
- }
- return ergebnis2;}
- public static void main(String[] args) {
- String zahl;
- String Potenz;
- zahl = JOptionPane.showInputDialog("Geben Sie bitte eine Zahl ein");
- Potenz = JOptionPane
- .showInputDialog("Geben Sie bitte eine Zahl als Potenz ein.");
- int zahl2 = Integer.parseInt(zahl);
- int Potenz2 = Integer.parseInt(Potenz);
- int ergebnis = potenz.berechnePotenz(zahl2, Potenz2);
- JOptionPane.showMessageDialog(null, "Das Ergebnis ist " + ergebnis);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement