Computer Science 101 - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Computer Science 101

Description:

Computer Science 101. The If Statement. Java's Relational Operators. Primitive Conditions. Conditions are expressions which evaluate to true or false. ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 10
Provided by: tomwh
Category:

less

Transcript and Presenter's Notes

Title: Computer Science 101


1
Computer Science 101
  • The If Statement

2
Javas Relational Operators
3
Primitive Conditions
  • Conditions are expressions which evaluate to true
    or false.
  • One kind of condition is the comparison of two
    numerical values of the same type.
  • Examples
  • Payrate gt 10
  • (x10) (yz -8)

4
The basic If-Statement
  • The syntax for the If-Statement is
    if (condition) statement
  • The semantics are as expected -
  • the condition is evaluated
  • if the condition is true, the statement is
    executed
  • The statement may be compound - more than one
    statement enclosed in a pair of

5
If-Statement Semantics
6
If-Statement examples
  • if (yearsWorked gt 10) bonus 1000
  • if (age gt 65) total 0.9 total
    numSeniors numSeniors 1

7
The If-else-Statement
  • The syntax for the If-Else-Statement is
    if (condition) statement-1
    else statement-2
  • The semantics are as expected -
  • the condition is evaluated
  • if the condition is true, then statement-1 is
    executed otherwise, statement-2 is executed
  • Either statement may be compound - more than one
    statement enclosed in a pair of

8
If-Else-Statement examples
  • if (yearsWorked gt 10) bonus 1000
    else bonus 500
  • if (age gt 0) total 0.9 total
    numSeniors numSeniors 1 else
    nonSeniors nonSeniors 1

9
While I'm resting, you boys ...
Write a Comment
User Comments (0)
About PowerShow.com