package de.joethei.java1; import java.util.Random; import java.util.Scanner; public class Zettel4 { public static void main(String[] args) { aufgabe1a(); aufgabe1b(); aufgabe2(); aufgabe3(); aufgabe4(); aufgabe5(); aufgabe6(); aufgabe7a(); aufgabe7b(); aufgabe7c(); aufgabe7d(); aufgabe8a(); aufgabe8b(); aufgabe8c(); aufgabe8d(); aufgabe8e(); aufgabe8f(); } private static void aufgabe1a() { for(int i = 1; i <= 10; i++) { System.out.println(i + " x " + i + " x " + i + " = " + i*i*i); } } private static void aufgabe1b() { for(int i = 1; i <= 7; i++) { System.out.println(i + " x " + (i + 1) + " x " + (i + 2) + " = " + i*(i + 1)*(i + 2)); } } private static void aufgabe2() { Scanner scanner = new Scanner(System.in); System.out.println("Startkapital eingeben"); double start = scanner.nextLong(); System.out.println("Zinssatz angeben"); double zins = scanner.nextDouble(); double end10 = start * Math.pow((1 + zins / 100), 10); System.out.println("In 10 Jahren ist das Kapital: " + end10); double end = start; int i = 0; while (end <= start * 2) { i++; end = start * Math.pow((1 + zins / 100), i); } System.out.println("Das Kapital wird in " + i + " Jahren verdoppelt sein."); System.out.println("Das Kapital wird " + end + " betragen"); } private static void aufgabe3() { Scanner scanner = new Scanner(System.in); System.out.println("Name:"); String name = scanner.next(); System.out.println("Alter:"); int age = scanner.nextInt(); System.out.println("Geschlecht (m/w):"); String gender = scanner.next(); int greetings = age/4; String greeting; if(age < 18) greeting = "Hallo "; else if(gender.equalsIgnoreCase("w")) greeting = "Guten Tag Frau "; else if(gender.equalsIgnoreCase("m")) greeting = "Guten Tag Herr "; else greeting = "Nicht definiert"; if(greetings <= 3) greetings = 3; for(int i = greetings; i >= 1; i--) { System.out.println(greeting + name + "!"); } } private static void aufgabe4() { Scanner scanner = new Scanner(System.in); System.out.println("Höhe angeben"); int height = scanner.nextInt(); int spaces = height * 2; int bottom = spaces; for(int i = 0; i <= height-1; i++) { spaces--; for (int j = 0; j <= spaces; j++) { System.out.print(" "); } for (int j = 0; j <= i; j++) { System.out.print("* "); } System.out.println(); } for (int i = 0; i < 2 ; i++) { for (int j = 0; j <= bottom-1; j++) { System.out.print(" "); } System.out.println("*"); } } private static void aufgabe5() { Scanner scanner = new Scanner(System.in); int number = new Random().nextInt(100); System.out.println("Raten Sie die Zahl"); //System.out.println("Die Zahl ist " + number); int tries = 1; while (scanner.nextInt() != number) { tries++; } switch (tries) { case 1: case 2: case 3: System.out.println("Einfach toll gemacht. Nahezu genial"); break; case 4: case 5: case 6: System.out.println("Gut gemacht Sie sind fast wie Einstein."); break; case 7: case 8: System.out.println("Wahr wohl doch nicht so leicht..."); break; default: System.out.println("Üben üben üben... Es wird schon!"); break; } } private static void aufgabe6() { Scanner scanner = new Scanner(System.in); System.out.println("Was soll berechnet werden (Kreis, Quadrat, Dreieck) ?"); String type = scanner.next(); if(type.equalsIgnoreCase("kreis")) { System.out.println("Durchmesser des Kreises angeben:"); System.out.println("Die Fläche des Kreises beträgt: " + ((Math.pow(scanner.nextInt(), 2) * Math.PI) / 4)); } if(type.equalsIgnoreCase("quadrat")) { System.out.println("Länge einer Seite angeben:"); System.out.println("Die Fläche des Quadrats beträgt: " + Math.pow(scanner.nextInt(), 2)); } if(type.equalsIgnoreCase("dreieck")) { System.out.println("Länge der Seite a angeben:"); int a = scanner.nextInt(); System.out.println("Höhe angeben:"); System.out.println("Die Fläche des Kreises beträgt: " + (a * scanner.nextInt()) / 2); } } private static void aufgabe7a() { for(int i = 1; i <= 50; i++) { System.out.print(i + " "); } System.out.println(); } private static void aufgabe7b() { for(int i = 1; i <= 99; i+=2) { System.out.print(i + " "); } System.out.println(); } private static void aufgabe7c() { int j; int m = 0; int n = 1; for(int i = 1; i <= 10; i++) { j = m + n; m = n; n = j; System.out.print(j + " "); } System.out.println(); } private static void aufgabe7d() { int j = 0; for (int i = 1; i <= 50; i++) { if((i % 2) == 0) j = j + 3; else j = j+1; System.out.print(j + " "); } System.out.println(); } private static void aufgabe8a() { for (int i = 0; i < 8; i++) { for (int j = 0; j < 15; j++) { System.out.print("+"); } System.out.println(); } } private static void aufgabe8b() { for (int i = 0; i < 8; i++) { for (int j = 0; j < 15; j++) { if((i % 2) == 0) System.out.print("+"); else System.out.print("-"); } System.out.println(); } } private static void aufgabe8c() { for (int i = 0; i < 8; i++) { for (int j = 0; j < 16; j++) { if((j <= 7 && i <= 3) || j >= 8 && i >=4) System.out.print("."); else System.out.print("+"); } System.out.println(); } } private static void aufgabe8d() { int points = 14; for (int i = 0; i < 8; i++) { for (int j = 0; j < points; j++) { System.out.print("."); } for (int j = 0; j < (14 - points); j++) { System.out.print("+"); } System.out.println(); points -=2; } } private static void aufgabe8e() { for (int i = 0; i < 10; i++) { for (int j = 0; j < 9-i; j++) { System.out.print("."); } for (int j = 0; j < i*2+1; j++) { System.out.print("+"); } for (int j = 0; j < 9-i; j++) { System.out.print("."); } System.out.println(); } } private static void aufgabe8f() { for (int i = 0; i < 10; i++) { for (int j = 0; j < 9-i; j++) { System.out.print("."); } for (int j = 0; j < i*2+1; j++) { if((j % 2) == 0) System.out.print("+"); else System.out.print("O"); } for (int j = 0; j < 9-i; j++) { System.out.print("."); } System.out.println(); } } }