Created
May 16, 2016 18:32
-
-
Save eSlider/08376e9e5c72574022783428a51bd424 to your computer and use it in GitHub Desktop.
Power.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.util.InputMismatchException; | |
public class Power | |
{ | |
public static int hoch(int x, int y) | |
{ | |
int result; | |
if ( y > 0 ) { | |
result = x * hoch(x, y-1); | |
} else { | |
result = 1; | |
} | |
return result; | |
} | |
public static int catchNumber(String title) | |
{ | |
int number; | |
Scanner scan = new Scanner(System.in); | |
try { | |
System.out.print(title); | |
number = scan.nextInt(); | |
} catch (InputMismatchException e) { | |
System.out.println("Die Eingabe ist falsch, versuchen Sie es noch einmal!"); | |
number = catchNumber(title); | |
} | |
return number; | |
} | |
public static void main(String[]args) | |
{ | |
System.out.println("Das Ergebnis: " + hoch( | |
catchNumber("Bitte geben Sie x: "), | |
catchNumber("Bitte geben Sie y: ") | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment