SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Chapter 3:  Program Statements  Presentation slides for Java Software Solutions for AP* Computer Science by John Lewis, William Loftus, and Cara Cocking Java Software Solutions is published by Addison-Wesley Presentation slides are copyright 2002 by John Lewis, William Loftus, and Cara Cocking. All rights reserved. Instructors using the textbook may use and modify these slides for pedagogical purposes. *AP is a registered trademark of The College Entrance Examination Board which was not involved in the production of, and does not endorse, this product.
Flow of Control ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Conditional Statements ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The if Statement ,[object Object],if (  condition  ) statement ; if   is a Java reserved word The  condition  must be a boolean expression. It must evaluate to either true or false. If the  condition  is true, the  statement  is executed. If it is false, the  statement  is skipped.
The if Statement ,[object Object],if (sum > MAX) delta = sum - MAX; System.out.println ("The sum is " + sum); First, the condition is evaluated. The value of  sum is either greater than the value of  MAX , or it is not. If the condition is true, the assignment statement is executed. If it is not, the assignment statement is skipped. Either way, the call to  println  is executed next. ,[object Object]
Logic of an if statement condition evaluated false statement true
Boolean Expressions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The if-else Statement ,[object Object],if (  condition  ) statement1 ; else statement2 ; ,[object Object],[object Object],[object Object]
Logic of an if-else statement condition evaluated statement1 true false statement2
Block Statements ,[object Object],[object Object],[object Object],[object Object],[object Object]
Nested if Statements ,[object Object],[object Object],[object Object],[object Object],[object Object]
Logical Operators ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Logical NOT ,[object Object],[object Object],[object Object],true false false true !a a
Logical AND and Logical OR ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Truth Tables ,[object Object],[object Object],false false false false true false true false true false false true true true true true a || b a && b b a
Logical Operators ,[object Object],if (total < MAX+5 && !found) System.out.println (&quot;Processing…&quot;); ,[object Object],[object Object],[object Object]
Short Circuited Operators ,[object Object],[object Object],if (count != 0 && total/count > MAX) System.out.println (&quot;Testing…&quot;); ,[object Object]
Truth Tables ,[object Object],false false true true true true false true false false true false false true false false total < MAX && !found !found found total < MAX
Comparing Characters ,[object Object],[object Object],[object Object],if ('+' < 'J') System.out.println (&quot;+ is less than J&quot;); ,[object Object]
Comparing Strings ,[object Object],[object Object],[object Object],[object Object]
Lexicographic Ordering ,[object Object],[object Object],[object Object],[object Object],[object Object]
Comparing Float Values ,[object Object],[object Object],[object Object],[object Object],if (Math.abs(f1 - f2) < 0.00001) System.out.println (&quot;Essentially equal.&quot;);
More Operators ,[object Object],[object Object],[object Object],[object Object]
Increment and Decrement ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Assignment Operators ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Assignment Operators ,[object Object],Operator += -= *= /= %= Example x += y x -= y x *= y x /= y x %= y Equivalent To x = x + y x = x - y x = x * y x = x / y x = x % y
Assignment Operators ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Assignment Operators ,[object Object],[object Object],[object Object]
Repetition Statements ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The while Statement ,[object Object],while (  condition  ) statement ; The  statement  is executed repeatedly until the  condition  becomes false. while  is a reserved word If the  condition  is true, the  statement  is executed. Then the  condition  is evaluated again.
Logic of a while Loop statement true condition evaluated false
The while Statement ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Infinite Loops ,[object Object],[object Object],[object Object],[object Object],[object Object]
Nested Loops ,[object Object],[object Object],[object Object],[object Object]
The StringTokenizer Class ,[object Object],[object Object],[object Object],[object Object]
The StringTokenizer Class ,[object Object],[object Object],[object Object],[object Object]
The for Statement ,[object Object],for (  initialization  ;  condition  ;  increment  ) statement ; Reserved word The  initialization is executed once before the loop begins The  statement  is executed until the condition  becomes false The   increment   portion is executed at the end of each iteration The  condition - statement - increment  cycle is executed repeatedly
The for Statement ,[object Object],initialization ; while (  condition  ) { statement ; increment ; }
Logic of a for loop statement true condition evaluated false increment initialization
The for Statement ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The for Statement ,[object Object],[object Object],[object Object],[object Object],[object Object]
Choosing a Loop Structure ,[object Object],[object Object]
Program Development ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Program Development ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Program Development ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Program Development ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Program Development ,[object Object],[object Object],[object Object],[object Object]
More Drawing Techniques ,[object Object],[object Object],[object Object],[object Object]
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

Fundamental programming structures in java
Fundamental programming structures in javaFundamental programming structures in java
Fundamental programming structures in java
Shashwat Shriparv
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
Suchit Patel
 
Control structures in Java
Control structures in JavaControl structures in Java
Control structures in Java
Ravi_Kant_Sahu
 

Was ist angesagt? (19)

Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
 
+2 Computer Science - Volume II Notes
+2 Computer Science - Volume II Notes+2 Computer Science - Volume II Notes
+2 Computer Science - Volume II Notes
 
Fundamental programming structures in java
Fundamental programming structures in javaFundamental programming structures in java
Fundamental programming structures in java
 
Basic
BasicBasic
Basic
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
 
8 if
8 if8 if
8 if
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
 
Operators in java presentation
Operators in java presentationOperators in java presentation
Operators in java presentation
 
05 operators
05   operators05   operators
05 operators
 
The Go Programing Language 1
The Go Programing Language 1The Go Programing Language 1
The Go Programing Language 1
 
Of Lambdas and LINQ
Of Lambdas and LINQOf Lambdas and LINQ
Of Lambdas and LINQ
 
Control structures in Java
Control structures in JavaControl structures in Java
Control structures in Java
 
Java se 8 fundamentals
Java se 8 fundamentalsJava se 8 fundamentals
Java se 8 fundamentals
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NET
 
Control structures i
Control structures i Control structures i
Control structures i
 
Fundamentals of Computing and C Programming - Part 2
Fundamentals of Computing and C Programming - Part 2Fundamentals of Computing and C Programming - Part 2
Fundamentals of Computing and C Programming - Part 2
 
Java 2
Java 2Java 2
Java 2
 

Andere mochten auch (10)

Ap Power Point Chpt9
Ap Power Point Chpt9Ap Power Point Chpt9
Ap Power Point Chpt9
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4
 
First Principles Of Cs Instruction
First Principles Of Cs InstructionFirst Principles Of Cs Instruction
First Principles Of Cs Instruction
 
JavaYDL20
JavaYDL20JavaYDL20
JavaYDL20
 
Lecture 4 recursion
Lecture 4    recursionLecture 4    recursion
Lecture 4 recursion
 
Ap Power Point Chpt7
Ap Power Point Chpt7Ap Power Point Chpt7
Ap Power Point Chpt7
 
Recursion Lecture in Java
Recursion Lecture in JavaRecursion Lecture in Java
Recursion Lecture in Java
 
Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6
 
Ap Power Point Chpt1
Ap Power Point Chpt1Ap Power Point Chpt1
Ap Power Point Chpt1
 
Internet principles of operation
Internet principles of operationInternet principles of operation
Internet principles of operation
 

Ähnlich wie Ap Power Point Chpt3 B

Chapter 4 flow control structures and arrays
Chapter 4 flow control structures and arraysChapter 4 flow control structures and arrays
Chapter 4 flow control structures and arrays
sshhzap
 
Java Script Language Tutorial
Java Script Language TutorialJava Script Language Tutorial
Java Script Language Tutorial
vikram singh
 
Chapter 4.1
Chapter 4.1Chapter 4.1
Chapter 4.1
sotlsoc
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
bajiajugal
 

Ähnlich wie Ap Power Point Chpt3 B (20)

slides03.ppt
slides03.pptslides03.ppt
slides03.ppt
 
Ch04
Ch04Ch04
Ch04
 
Chapter 4 flow control structures and arrays
Chapter 4 flow control structures and arraysChapter 4 flow control structures and arrays
Chapter 4 flow control structures and arrays
 
Java input Scanner
Java input Scanner Java input Scanner
Java input Scanner
 
M C6java5
M C6java5M C6java5
M C6java5
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
LOOPS AND DECISIONS
LOOPS AND DECISIONSLOOPS AND DECISIONS
LOOPS AND DECISIONS
 
MODULE_2_Operators.pptx
MODULE_2_Operators.pptxMODULE_2_Operators.pptx
MODULE_2_Operators.pptx
 
Conditonals.pdf
Conditonals.pdfConditonals.pdf
Conditonals.pdf
 
Java Script Language Tutorial
Java Script Language TutorialJava Script Language Tutorial
Java Script Language Tutorial
 
Lecture 07.pptx
Lecture 07.pptxLecture 07.pptx
Lecture 07.pptx
 
Chapter 4.1
Chapter 4.1Chapter 4.1
Chapter 4.1
 
Chapter 04
Chapter 04Chapter 04
Chapter 04
 
GE3151 PSPP UNIT III QUESTION BANK.docx.pdf
GE3151 PSPP UNIT III QUESTION BANK.docx.pdfGE3151 PSPP UNIT III QUESTION BANK.docx.pdf
GE3151 PSPP UNIT III QUESTION BANK.docx.pdf
 
3.pdf
3.pdf3.pdf
3.pdf
 
Control All
Control AllControl All
Control All
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
 
Java Programming
Java Programming Java Programming
Java Programming
 
C operators
C operatorsC operators
C operators
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

Ap Power Point Chpt3 B

  • 1. Chapter 3: Program Statements Presentation slides for Java Software Solutions for AP* Computer Science by John Lewis, William Loftus, and Cara Cocking Java Software Solutions is published by Addison-Wesley Presentation slides are copyright 2002 by John Lewis, William Loftus, and Cara Cocking. All rights reserved. Instructors using the textbook may use and modify these slides for pedagogical purposes. *AP is a registered trademark of The College Entrance Examination Board which was not involved in the production of, and does not endorse, this product.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. Logic of an if statement condition evaluated false statement true
  • 7.
  • 8.
  • 9. Logic of an if-else statement condition evaluated statement1 true false statement2
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31. Logic of a while Loop statement true condition evaluated false
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39. Logic of a for loop statement true condition evaluated false increment initialization
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.