Skip to content

Instantly share code, notes, and snippets.

@eSlider
Created May 16, 2016 18:32
Show Gist options
  • Save eSlider/08376e9e5c72574022783428a51bd424 to your computer and use it in GitHub Desktop.
Save eSlider/08376e9e5c72574022783428a51bd424 to your computer and use it in GitHub Desktop.
Power.java
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