Die Präsentation wird geladen. Bitte warten

Die Präsentation wird geladen. Bitte warten

Verzweigung.

Ähnliche Präsentationen


Präsentation zum Thema: "Verzweigung."—  Präsentation transkript:

1 Verzweigung

2 Struktogramm – Normsprache - Syntax
Wenn Bedingung erfüllt dann tue    { Anweisungsblock}  sonst tue    {Anweisungsblock} if(<Bedingung>) {    <Anweisungs-Block> } else {    <Anweisungs-Block> }   November 2005 Informatik Grundkurs mit Java (C) MPohlig 2005

3 Die Farbe der Turtle wird richtungsabhängig
public void zeichne() {    if (t1.getOrientation()>180){      t1.setColor(Color.RED);    }    else {      t1.setColor(Color.BLUE);    }    t1.forward(40);    t1.right(60);  } Übung November 2005 Informatik Grundkurs mit Java (C) MPohlig 2005

4 Informatik Grundkurs mit Java (C) MPohlig 2005
Die Ulam-Folge Gebe Zahl vor Wiederhole       wenn Zahl gerade dann halbiere sie       sonst nimm sie mal 3 und füge 1 hinzu if (i % 2 ==0){    i = i/2; } else{    i = i*3+1; } November 2005 Informatik Grundkurs mit Java (C) MPohlig 2005

5 Informatik Grundkurs mit Java (C) MPohlig 2005
Das Ulam-Programm import info1.*; public class Ulam {     public static void main (String[] args) {      int i = 23;             System.out.println(i);         }  } System.out.print("Ganze Zahl > 1: "); int i = Console.in.readInt();        while (i != 1){ } if (i % 2 ==0){    i = i/2; } else{    i = i*3+1; } November 2005 Informatik Grundkurs mit Java (C) MPohlig 2005

6 Informatik Grundkurs mit Java (C) MPohlig 2005
Das abs-Programm import info1.*;  public class DemoAbs {      public static void main (String[] args) {      System.out.print("Geben Sie eine ganze Zahl ein: ");      int x = Console.in.readInt();      if (x >= 0){        System.out.println("abs("+x+") = "+x);      }      else {        System.out.println("abs("+x+") = "+(-x));      }    }  } “…“ Wert einer Variablen Konkatenation November 2005 Informatik Grundkurs mit Java (C) MPohlig 2005

7 Das Maximum zweier Zahlen
import info1.*;   public class DemoMax2 {      public static void main (String[] args) {      System.out.print("Geben a ein: ");      int a = Console.in.readInt();      System.out.print("Geben b ein: ");      int b = Console.in.readInt();      int max;      if (a>=b){        max = a;      }      else{        max = b;      }      System.out.println("Max("+a+","+b+") = "+max);    }  } November 2005 Informatik Grundkurs mit Java (C) MPohlig 2005

8 Das Maximum dreier eingegebener Zahlen
public static void main (String[] args) {   System.out.print("Geben a ein: ");   int a = Console.in.readInt();   System.out.print("Geben b ein: ");   int b = Console.in.readInt();   System.out.print("Geben c ein: ");   int c = Console.in.readInt();   int max;   if (a>=b){     max = a;   }   else{     max = b;   }   if (c>max){     max = c;   }   System.out.println("Max("+a+","+b+","+c+") = "+max); } November 2005 Informatik Grundkurs mit Java (C) MPohlig 2005


Herunterladen ppt "Verzweigung."

Ähnliche Präsentationen


Google-Anzeigen