From b07e5df91d7de76041546715b454e5dc42bd3115 Mon Sep 17 00:00:00 2001 From: Alexander Kimmig Date: Tue, 10 Oct 2023 11:06:54 +0200 Subject: [PATCH] Dateien nach "/" hochladen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Arbeitsblätter 2.1 bis 2.3 --- AB_2_1.java | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ AB_2_2.java | 62 +++++++++++++++++++++++++++++++++++++++++++++ AB_2_3.java | 51 +++++++++++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 AB_2_1.java create mode 100644 AB_2_2.java create mode 100644 AB_2_3.java diff --git a/AB_2_1.java b/AB_2_1.java new file mode 100644 index 0000000..4d0f1f8 --- /dev/null +++ b/AB_2_1.java @@ -0,0 +1,72 @@ +import java.util.Scanner; + +/** + * Beschreiben Sie hier die Klasse AB_2_1. + * + * @author (Ihr Name) + * @version (eine Versionsnummer oder ein Datum) + */ +public class AB_2_1 +{ + /** + * Gibt einen eingegebenen Text in umgekehrter Reihenfolge + * auf der Konsole aus + * + * @param text Text der ausgegeben werden soll + */ + public static void spiegeln(String text) { + // for-Schleife beginnt hinten und zählt rückwärts + for(int i = text.length() - 1; i >= 0; i--) { + System.out.print(text.charAt(i)); + } + } + + /** + * Rechnet eine Sekundenangabe in Jahre, Tage, Stunden, + * Minuten und Sekunden um + * + * @param time Sekunden + */ + public static void umrechnen(int time) { + System.out.println(time + " Sekunden entsprechen:"); + + // rechne Sekunden aus + int sekunden = time % 60; + time = (time - sekunden) / 60; + + // rechne Minuten aus + int minuten = time % 60; + time = (time - minuten) / 60; + + // rechne Stunden aus + int stunden = time % 24; + time = (time - stunden) / 24; + + // rechne Tage aus + int tage = time % 365; + time = (time - tage) / 365; + + System.out.println(time + " Jahren,"); + System.out.println(tage + " Tagen,"); + System.out.println(stunden + " Stunden,"); + System.out.println(minuten + " Minuten und"); + System.out.println(sekunden + " Sekunden."); + } + + /** + * gibt das kleine 1x1 auf der Konsole aus + */ + public static void einmaleins() { + for (int a = 1; a <= 10; a++) { + for (int b = 1; b <= 10; b++) { + // falls Zahl zu kurz, mit Leerzeichen auffüllen + if (a*b < 10) System.out.print(" "); + + // Zahl ausgeben + System.out.print(a*b + " "); + } + // Zeilenumbruch + System.out.println(); + } + } +} diff --git a/AB_2_2.java b/AB_2_2.java new file mode 100644 index 0000000..467b0f4 --- /dev/null +++ b/AB_2_2.java @@ -0,0 +1,62 @@ + +/** + * Beschreiben Sie hier die Klasse AB_2_2. + * + * @author (Ihr Name) + * @version (eine Versionsnummer oder ein Datum) + */ +public class AB_2_2 +{ + /** + * Berechnet die Summe + * + * @param a erste Zahl + * @param b zweite Zahl + * @return Summe aus a und b + */ + public static int summe(int a, int b) { + return a + b; + } + + /** + * überprüft, ob eine Zahl eine Primzahl ist + * + * @param a zu überprüfende Zahl + * @return Zahl ist Primzahl + */ + public static boolean istPrim(int a) { + for(int n = 2; n < Math.sqrt(a); n++) { + if (a % n == 0) return false; + } + return true; + } + + /** + * sucht Primzahl-Doubletten + * + * @param min ab welcher Zahl soll gesucht werden + */ + public static void primDoublette(int min) { + if (min % 2 == 0) min++; + while(!istPrim(min) || !istPrim(min+2)) { + min += 2; + } + + System.out.println(min + " und " + (min+2) + " gefunden!"); + } + + /** + * gibt Pythagoräische Tripel auf der Konsole aus + */ + public static void tripel() { + for(int a = 1; a < 100; a++) { + for(int b = a; b < 100; b++) { + for(int c = b; c < 100; c++) { + if (a*a + b*b == c*c) { + System.out.println(a + "^2 + " + b + "^2 = " + c + "^2"); + } + } + } + } + } +} diff --git a/AB_2_3.java b/AB_2_3.java new file mode 100644 index 0000000..d2b9867 --- /dev/null +++ b/AB_2_3.java @@ -0,0 +1,51 @@ + +/** + * Beschreiben Sie hier die Klasse AB_2_3. + * + * @author (Ihr Name) + * @version (eine Versionsnummer oder ein Datum) + */ +public class AB_2_3 +{ + /** + * Berechnet die Nullstelle einer linearen Gleichung y=mx+c + * und gibt sie auf der Konsole aus + * + * @param m Steigung + * @param c y-Achsenabschnitt + */ + public static void linear(float m, float c) { + if (m == 0) { + if (c == 0) System.out.println("Unendlich viele Nullstellen"); + else System.out.println("keine Nullstelle"); + return; + } + float x= - c / m; + System.out.println("Nullstelle: ("+x+"|0)"); + } + + /** + * berechnet die Nullstellen einer quadratischen Funktion + * y=ax^2+bx+c und gibt sie auf der Konsole aus. + * + * @param a quadratischer Koeffizient + * @param b linearer Koeffizient + * @param c y-Achsenabschnitt + */ + public static void quadrat(float a, float b, float c) { + float D = b*b - 4*a*c; + if (D < 0) System.out.println("keine Nullstellen"); + double x1 = (-b + Math.sqrt(D))/(2*a); + double x2 = (-b - Math.sqrt(D))/(2*a); + if (D == 0) System.out.println("eine Nullstellen bei ("+x1+"|0)"); + else System.out.println("Nullstellen bei ("+x1+"|0) und ("+x2+"|0)"); + } + + public static int glaeser(int n) { + int sum = 0; + for(int i=2; i<=n; i++) { + sum += i*(i-1)/2; + } + return sum; + } +}