Download presentation
Presentation is loading. Please wait.
Published byVanessa Parks Modified over 9 years ago
1
JAVA PROGRAMMING Control Flow
2
Jeroo: Finish Activities 1-7 Finish InputTest program w/changes
3
Review test results
4
Conditional Statements: Statements are executed based on a condition that is evaluated.
5
Conditional Statements: if if else if else if while do for switch break continue
6
Conditional Statements “if”: if (condition) statement or If (condition) { statements }
7
Conditional Statements “if”: if (yourGrade >= 90) System.out.println(“Your grade is an ‘A’”); if (yourGrade < 60) System.out.println(“Your grade is an ‘F’”);
8
Conditional Statements “if”: yourGrade >= 90 Print “Your grade is an A” termGrade += yourGrade NO YES
9
Conditional Statements “if”: if (yourGrade >= 90) { termGrade += yourGrade; System.out.println(“You’re grade is an ‘A’”); }
10
Conditional Statements “if-else”: yourGrade >= 90 Print “Your grade is an A” termGrade += yourGrade NO YES Print “Try harder next time”
11
Conditional Statements “if-else”: if (yourGrade >= 90) { termGrade += yourGrade; System.out.println(“Your grade is an ‘A’”); } else { System.out.println(“Try harder next time”); }
12
Conditional Statements “if-else-if”: termGrade += yourGrade if (termGrade >= 90) { System.out.println(“You’re grade is an ‘A’”); } else if (termGrade >= 80) { System.out.println(“You’re grade is an ‘B’”); } else if (termGrade >= 70) { System.out.println(“You’re grade is an ‘C’”); } else if (termGrade >= 60) { System.out.println(“You’re grade is an ‘D’”); } else { System.out.println(“You’re grade is an ‘F’”); }
13
Conditional Statements “if-else-if”: yourGrade >= 90 NO YES Print “Your grade is an A” yourGrade >= 80 yourGrade >= 70 Print “Your grade is an B” Print “Your grade is an C” NO YES
14
While Loop customerCount < 20 customerCount ++ “Ride Full” doorSensor True NO YES NO YES
15
While Loop: While (customerCount < 20) { If (doorSensor) customerCount ++; } System.out.println(“Ride is Full”);
16
Do While Loop: customerCount < 20 customerCount ++ “Ride Full” doorSensor True NO YES NO YES
17
Do While Loop: do { If (doorSensor) customerCount ++; } While (customerCount < 20) System.out.println(“Ride is Full”);
18
For Loop: for (int i = 1; i <= 10; i++) System.out.println(i);
19
switch: Scanner in = new Scanner(System.in); System.out.print(“Select an option (1, 2, 3, 4) “); int choice = in.nextInt(); switch (choice) { case 1: … break; case 2: … break; case 3: … break; case 4: … break; Default: … Break; }
20
Flowcharting:
21
Begin Just a Marker to show where the program begins. A A A connector to another area on the same page of a flowchart. 1 1 A connector to another page of the flowchart. END Just a Marker to show where the program ends.
22
Flowcharting : ? Yes or True No or False ? Yes or True No or False Decision based on a comparison to cause a branch in the logic.
23
Flowcharting : Do this! Equations, Declarations, Initializations, etc
24
Flowcharting : I/O to the program INPUT OUTPUT
25
Flowcharting : Flowchart the following scenario to be written in Java code: Grade Averaging Program: Prompt user to Input a grade Input the grade Sum the grade into a grade total Count the number of grades entered Repeat (loop!) until user enters a set value to terminate input process Divide the grade total by the count Display the average with text to explain the result
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.