Flowlines Action Symbols total= total+ grade; counter= counter+ 1 Connector Symbols Flowcharting Javas sequence structure. Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 6 add grade to total total = total + grade; add 1 to counter counter = counter + 1 ; Flowcharting Java’s sequence structure. Flowlines Action Symbols Connector Symbols
Decision Symbol true grade >=60 print Passed false Flowcharting the single-selection if structure Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 7 grade >= 60 true false print “Passed” Flowcharting the single-selection if structure. Decision Symbol
Selection Statements >if Statements switch statements Conditional Operators Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 8 Selection Statements ➢ if Statements ➢ switch Statements ➢ Conditional Operators
Simple if Statements if (radius >=0)3 area radius radius PI if(booleanExpression)i System. out. println("The area"+ statement(s) for the circle of radi radius +iS"+ area false false E Statement(s) System. out println("The area for the circle of " radius"+radius +"is"+ area (A) Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 9 Simple if Statements Boolean Expression true Statement(s) false (radius >= 0) true area = radius * radius * PI; System.out.println("The area for the circle of " + "radius " + radius + " is " + area); false (A) (B) if (booleanExpression) { statement(s); } if (radius >= 0) { area = radius * radius * PI; System.out.println("The area" + “ for the circle of radius " + radius + " is " + area); }
Note Outer parentheses required Braces can be omitted if the block contains a single f((i>0)&&(i<10)) System. out.println("i is an "+Equivalent if ((i >0)&&(i 10)) System. out. printin("i isan integer between 0 and 10")i integer between 0 and 10)i Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 10 Note if ((i > 0) && (i < 10)) { System.out.println("i is an " + + "integer between 0 and 10"); } (a) Equivalent (b) if ((i > 0) && (i < 10)) System.out.println("i is an " + + "integer between 0 and 10"); Outer parentheses required Braces can be omitted if the block contains a single statement