111 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Java
		
	
	
			
		
		
	
	
			111 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Java
		
	
	
| /**
 | |
|  * Beschreiben Sie hier die Klasse Übungen.
 | |
|  * 
 | |
|  * @author (Ihr Name) 
 | |
|  * @version (eine Versionsnummer oder ein Datum)
 | |
|  */
 | |
| import java.util.Scanner;
 | |
| public class Übungen
 | |
| {
 | |
|   public static void Aufgabe1() {
 | |
|       System.out.println("Hallo");
 | |
|       String test = "Hello World!";
 | |
|       
 | |
|       System.out.println (test.length());
 | |
|       System.out.println (test.charAt(1));
 | |
|   }
 | |
|   public static String textRückwärts1 () {
 | |
|       String text = "Hello World!";
 | |
|       String ergebnis = "";
 | |
|       for (int i= text.length()-1; i>=0; i--)
 | |
|       {
 | |
|           ergebnis = ergebnis + text.charAt(i);
 | |
|       }
 | |
|       return ergebnis;
 | |
|   }
 | |
|   public static void SekundenInJahre2 () {
 | |
|       Scanner sc = new Scanner(System.in);
 | |
|       int sekunden = sc.nextInt();
 | |
|       int minuten = sekunden / 60;
 | |
|       int stunden = minuten / 60;
 | |
|       int tage = stunden / 24;
 | |
|       int jahre = tage / 365;
 | |
|       System.out.println (sekunden + " sekunden");
 | |
|       System.out.println (minuten + " minuten"); 
 | |
|       System.out.println (stunden + " stunden");
 | |
|       System.out.println (tage + " tage");
 | |
|       System.out.println (jahre + "jahre");
 | |
|   }
 | |
|   public static void kleinesEinmaleins3 () {
 | |
|       for (int a=1; a<=10; a++)
 | |
|     {
 | |
|         for (int b=1; b<=10; b++)
 | |
|         {
 | |
|             System.out.print(a*b + " ");
 | |
|         }
 | |
|         System.out.println (" ");
 | |
|     }
 | |
|   }
 | |
|   public static void Summe4 (int a, int b){
 | |
|       Scanner sc = new Scanner(System.in);
 | |
|       System.out.println (a*b);
 | |
|   }
 | |
|   public static boolean istPrim (int n) { //Primzahlen ja nein
 | |
|     Scanner sc = new Scanner(System.in);
 | |
|     boolean zahl = false;
 | |
|     for (int i=2; i<n; i++){
 | |
|         if (n % i== 0) { // % Rest --> wenn der Restwert von i = 0 ist ... 
 | |
|             zahl = false;
 | |
|             break; // beendet die Schleife direkt ohne weiter zu gehen
 | |
|         }
 | |
|         else {
 | |
|             zahl = true;
 | |
|         }
 | |
|     }
 | |
|     return zahl;
 | |
|   }
 | |
|   public static void istPrim2(){
 | |
|       Scanner sc = new Scanner(System.in);
 | |
|       int min = sc.nextInt();
 | |
|       while (true) {
 | |
|           if (istPrim(min)){
 | |
|               int min2 = min + 2;
 | |
|               if (istPrim(min2)){
 | |
|                   System.out.println(min + "und" + min2 + "sind Primzahl-Doubletten");
 | |
|                   break; // beendet die Schleife direkt
 | |
|               }
 | |
|               else {
 | |
|                   min = min + 1;
 | |
|               }
 | |
|           }
 | |
|       }
 | |
|   }
 | |
|   public static void pythagoräischeTripel(){
 | |
|       for (int a = 1; a <= 100; a++){
 | |
|          for (int b = 1; b <= 100; b++){
 | |
|              for (int c =1; c <= 100; c++) {
 | |
|                  if (c*c == a*a +b*b){
 | |
|                      System.out.println (a + " , " + b + " , " + c);
 | |
|                  }
 | |
|              }
 | |
|           }
 | |
|       }
 | |
|     }
 | |
|     public static void Nullstellen(){
 | |
|         Scanner sc = new Scanner(System.in);
 | |
|         float m = sc.nextInt();
 | |
|         float c = sc.nextInt();
 | |
|          if (c == 0 && m == 0) {
 | |
|                 System.out.println("unendlich viele Nullstellen");
 | |
|                 
 | |
|          }
 | |
|          else if (m ==0){
 | |
|                 System.out.println("keine Nullstellen");
 | |
|                 
 | |
|          }
 | |
|         
 | |
|         float x = (-c) /m;
 | |
|         System.out.println("Nullstelle ist: x= " + x);
 | |
|     }
 | |
| }
 |