Kommentare 1-3
							parent
							
								
									84a7f67f68
								
							
						
					
					
						commit
						073ac0f709
					
				
							
								
								
									
										24
									
								
								AB_2_1.java
								
								
								
								
							
							
						
						
									
										24
									
								
								AB_2_1.java
								
								
								
								
							|  | @ -8,24 +8,41 @@ import java.util.Scanner; | ||||||
|  */ |  */ | ||||||
| public class AB_2_1 | 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) { |     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--) { |         for(int i = text.length() - 1; i >= 0; i--) { | ||||||
|             System.out.print(text.charAt(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) { |     public static void umrechnen(int time) { | ||||||
|         System.out.println(time + " Sekunden entsprechen:"); |         System.out.println(time + " Sekunden entsprechen:"); | ||||||
| 
 | 
 | ||||||
|  |         // rechne Sekunden aus
 | ||||||
|         int sekunden = time % 60; |         int sekunden = time % 60; | ||||||
|         time = (time - sekunden) / 60; |         time = (time - sekunden) / 60; | ||||||
| 
 | 
 | ||||||
|  |         // rechne Minuten aus
 | ||||||
|         int minuten = time % 60; |         int minuten = time % 60; | ||||||
|         time = (time - minuten) / 60; |         time = (time - minuten) / 60; | ||||||
| 
 | 
 | ||||||
|  |         // rechne Stunden aus
 | ||||||
|         int stunden = time % 24; |         int stunden = time % 24; | ||||||
|         time = (time - stunden) / 24; |         time = (time - stunden) / 24; | ||||||
| 
 | 
 | ||||||
|  |         // rechne Tage aus
 | ||||||
|         int tage = time % 365; |         int tage = time % 365; | ||||||
|         time = (time - tage) / 365; |         time = (time - tage) / 365; | ||||||
| 
 | 
 | ||||||
|  | @ -36,12 +53,19 @@ public class AB_2_1 | ||||||
|         System.out.println(sekunden + " Sekunden."); |         System.out.println(sekunden + " Sekunden."); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * gibt das kleine 1x1 auf der Konsole aus | ||||||
|  |      */ | ||||||
|     public static void einmaleins() { |     public static void einmaleins() { | ||||||
|         for (int a = 1; a <= 10; a++) { |         for (int a = 1; a <= 10; a++) { | ||||||
|             for (int b = 1; b <= 10; b++) { |             for (int b = 1; b <= 10; b++) { | ||||||
|  |                 // falls Zahl zu kurz, mit Leerzeichen auffüllen
 | ||||||
|                 if (a*b < 10) System.out.print(" "); |                 if (a*b < 10) System.out.print(" "); | ||||||
|  |                  | ||||||
|  |                 // Zahl ausgeben
 | ||||||
|                 System.out.print(a*b + " "); |                 System.out.print(a*b + " "); | ||||||
|             } |             } | ||||||
|  |             // Zeilenumbruch
 | ||||||
|             System.out.println(); |             System.out.println(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
							
								
								
									
										21
									
								
								AB_2_2.java
								
								
								
								
							
							
						
						
									
										21
									
								
								AB_2_2.java
								
								
								
								
							|  | @ -7,10 +7,23 @@ | ||||||
|  */ |  */ | ||||||
| public class AB_2_2 | 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) { |     public static int summe(int a, int b) { | ||||||
|         return a + 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) { |     public static boolean istPrim(int a) { | ||||||
|         for(int n = 2; n < Math.sqrt(a); n++) { |         for(int n = 2; n < Math.sqrt(a); n++) { | ||||||
|             if (a % n == 0) return false; |             if (a % n == 0) return false; | ||||||
|  | @ -18,6 +31,11 @@ public class AB_2_2 | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * sucht Primzahl-Doubletten | ||||||
|  |      *  | ||||||
|  |      * @param min   ab welcher Zahl soll gesucht werden | ||||||
|  |      */ | ||||||
|     public static void primDoublette(int min) { |     public static void primDoublette(int min) { | ||||||
|         if (min % 2 == 0) min++; |         if (min % 2 == 0) min++; | ||||||
|         while(!istPrim(min) || !istPrim(min+2)) { |         while(!istPrim(min) || !istPrim(min+2)) { | ||||||
|  | @ -27,6 +45,9 @@ public class AB_2_2 | ||||||
|         System.out.println(min + " und " + (min+2) + " gefunden!"); |         System.out.println(min + " und " + (min+2) + " gefunden!"); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * gibt Pythagoräische Tripel auf der Konsole aus | ||||||
|  |      */ | ||||||
|     public static void tripel() { |     public static void tripel() { | ||||||
|         for(int a = 1; a < 100; a++) { |         for(int a = 1; a < 100; a++) { | ||||||
|             for(int b = a; b < 100; b++) { |             for(int b = a; b < 100; b++) { | ||||||
|  |  | ||||||
							
								
								
									
										15
									
								
								AB_2_3.java
								
								
								
								
							
							
						
						
									
										15
									
								
								AB_2_3.java
								
								
								
								
							|  | @ -7,6 +7,13 @@ | ||||||
|  */ |  */ | ||||||
| public class AB_2_3 | 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) { |     public static void linear(float m, float c) { | ||||||
|         if (m == 0) { |         if (m == 0) { | ||||||
|             if (c == 0) System.out.println("Unendlich viele Nullstellen"); |             if (c == 0) System.out.println("Unendlich viele Nullstellen"); | ||||||
|  | @ -17,6 +24,14 @@ public class AB_2_3 | ||||||
|         System.out.println("Nullstelle: ("+x+"|0)"); |         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) { |     public static void quadrat(float a, float b, float c) { | ||||||
|         float D = b*b - 4*a*c; |         float D = b*b - 4*a*c; | ||||||
|         if (D < 0) System.out.println("keine Nullstellen"); |         if (D < 0) System.out.println("keine Nullstellen"); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue