Java Programming: Loops and Logic, Slides of Java Programming

Various control statements in java programming, including if statements, relational operators, logical operators, and the switch statement. Topics include the use of code blocks, the else statement, nested if statements, logical expressions, and the conditional operator. Examples are provided for numbercheck.java, lettercheck.java, conditionalop.java, and scope.java.

Typology: Slides

2012/2013

Uploaded on 04/24/2013

baishali
baishali 🇮🇳

4

(2)

84 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Chapter 3: Loops and Logic
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Java Programming: Loops and Logic and more Slides Java Programming in PDF only on Docsity!

1

Chapter 3: Loops and Logic

2

Control Statements

  • If statement
  • Example NumberCheck.java
  • Relational operators (<, <=, >, >=, ==, !=)
  • Using code blocks with If
  • The else statement
  • Nested If
  • Example: LetterCheck.java

4

  • It has the following form and always returns a value of one of the two exps.
  • Logical exp? exp1:exp2;
  • Example: ConditionalOp.java
  • The switch statement can perform multiple selections.
  • Using the break statement
  • Local variables are visible only in limited scope
  • Example: Scope.java

Conditional Operator and switch

5

  • Different types (for, while, do—while)
  • Initialization, test, & increment conditions
  • Loop counters can be int or float
  • Nested loops, example Factorial.java
  • Break, continue, labeled break and continue
  • Assertion: “ assert logical-exp;
  • Compile with “-source 1.4” and run with “-ea”, example TryAssertions.java

Loops