public class SchleifenII_02_02_2021
{
  public SchleifenII_02_02_2021()
  { int beispiel = 17;
    if (istGerade(beispiel)) 
         System.out.println("Die Zahl " + beispiel + " ist gerade.");
    else System.out.println("Die Zahl " + beispiel + " ist ungerade.");
    
    System.out.println("Das Maximum der Zahlen 17 und 23 ist " + maximum(17, 23) + ".");
    
    int collatzLaenge = collatzAnzahl(beispiel);
    String ausgabe = "Mit dem Startwert " + beispiel;
    ausgabe = ausgabe + " ist die Folgenlaenge " + collatzLaenge + ".";
    System.out.println(ausgabe);
  }

  public int maximum(int zahl1, int zahl2)
  {  if(zahl1 > zahl2)
          return zahl1;
     else return zahl2;
  }  

  public boolean istGerade(int zahl)
  {  if(zahl % 2 == 0)
          return true;
     else return false;
     // Noch kuerzer: return (zahl % 2) == 0;
  }
  
  public int collatzAnzahl(int start)
  { // 3A + 1 - Problem
    int zahl = start;
    int anzahl = 1;
    while (zahl != 1) 
    {    if (zahl % 2 == 0)
              zahl = zahl / 2;
         else zahl = 3 * zahl + 1;    
         anzahl++;
    }
    return anzahl;
  }  
}
