public class Hauptklasse {



	private Hauptklasse() {
	}

	// per Schleife
	private void fakultaet1() {
		System.out.println("in fakultaet1");
		int n = 5;
		int produkt = 1;
		for (int i = 1; i <= n; i = i + 1) {
			produkt = produkt * i;
		}
		System.out.println(produkt);
	}

	// 1*2*3*4*5
	private int calcfakultaet2(int n) {
		System.out.println("n : " + n);
		if (n == 1) {
			System.out.println("Ende der reskursion");
			return 1;
		} else {
			int erg = n * calcfakultaet2(n - 1);
			System.out.println("n : " + n);
			return erg;
		}
	}

	private void fakultaet2() {
		System.out.println("\nin fakultaet2");
		int n = 5;
		int produkt = calcfakultaet2(n);
		System.out.println(produkt);
	}

	// per Schleife
	private void summe1() {
		System.out.println("in summe1");
		int n = 10;
		int summe = 0;
		for (int i = 1; i <= n; i = i + 1) {
			summe = summe + i;
		}
		System.out.println(summe);
	}

	private int calcsumme2(int n) {
		System.out.println("n1: " + n);
		if (n == 1) {
			System.out.println("ende Rekursion");
			return 1;
		} else {
			int erg = n + calcsumme2(n - 1);
			System.out.println("n2: " + n);
			return erg;
		}
	}

	private void summe2() {
		System.out.println("\nin summe2");
		int n = 10;
		int summe = calcsumme2(n);
		System.out.println(summe);
	}

	// per Schleife
	private void arraysumme1() {
		System.out.println("in arraysumme1");
		int[] feld = { 1, 2, 3, 4, 7 };
		int summe = 0;
		for (int i = 0; i < feld.length; i = i + 1) {
			summe = summe + feld[i];
		}
		System.out.println(summe);
	}

	private int arraycalcsumme2(int[] feld, int index) {
		System.out.println("index1: " + index);
		if (index == 0) {
			System.out.println("ende Rekursion");
			return feld[index];
		} else {
			int erg = feld[index] + arraycalcsumme2(feld, index - 1);
			System.out.println("index2: " + index);
			return erg;
		}
	}

	private void arraysumme2() {
		System.out.println("\nin arraysumme2");
		int[] feld = { 1, 2, 3, 4, 7 };
		int summe = arraycalcsumme2(feld, feld.length - 1);
		System.out.println(summe);
	}
	
	
	
	private void power1() {
		System.out.println("\nin power1");
		int x = 2;
		int n = 6;
		int erg=1;
		for (int i=0; i<n; i=i+1) {
			erg = erg * x;
		}		
		System.out.println("\nin erg: "+erg);
	}
	
	//   x� = x * x�
	private int calcpower2(int x, int n) {
		if (n==1) {
			return x;
		}
		return x * calcpower2(x,n-1);
	}
	
	private void power2() {
		System.out.println("\nin power2");
		int x = 2;
		int n = 6;
		int erg=calcpower2(x,n);
		
		System.out.println("\nin erg: "+erg);
	}
	
	

	public static void main(String[] args) {
		Hauptklasse instanz = new Hauptklasse();
		// instanz.fakultaet1();
		// instanz.fakultaet2();

		// instanz.summe1();
		// instanz.summe2();

		//instanz.arraysumme1();
		 //instanz.arraysumme2();
		instanz.power1();

	}

}