1 / 8

Verzweigung

Verzweigung. Struktogramm – Normsprache - Syntax. Wenn Bedingung erfüllt dann tue    { Anweisungsblock}  sonst tue    {Anweisungsblock}. if (<Bedingung>) {    <Anweisungs-Block> } else {    <Anweisungs-Block> }. Die Farbe der Turtle wird richtungsabhängig.

Download Presentation

Verzweigung

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Verzweigung

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

  4. Die Ulam-Folge Gebe Zahl vorWiederhole      wenn Zahl gerade dann halbiere sie      sonst nimm sie mal 3 und füge 1 hinzu 3 - 10 - 5 - 16 - 8 - 4 - 2 - 1 - 4 - 2 - 1 - 4 - 2 - 1.... 3 - 10 - 5 - 16 - 8 - 4 - 2 - 1 - 4 - 2 - 1 - 4 - 2 - 1.... 23 - 70 - 35 - 106 - 53 - 160 - 80 - 40 - 20 - 10 - 5 - 16 - 8 - 4 - 2 - 1 if (i % 2 ==0){   i = i/2;}else{   i = i*3+1;} Informatik Grundkurs mit Java (C) MPohlig 2005

  5. 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;} Informatik Grundkurs mit Java (C) MPohlig 2005

  6. 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 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);   } } 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);} Informatik Grundkurs mit Java (C) MPohlig 2005

More Related