New Microsoft Word Document
New Microsoft Word Document
****
Listing 2.2
If (radius < 0) {
} else {
****
BOOLEAN EXPRESSION:
Listing 3.1
Import java.util.Scanner;
}
}
Question:
(x > 0) = true
(x < 0) = false
(x != 0) = true
(x >= 0) = false
(x != 1) = false
boolean b = true;
int i =1;
IF STATEMENT
Type of If Statement
1. One-way if statement
If (Boolean-expression / condition) {
Statement(s);
}
If (Boolean-expression / condition) {
Statement(s) -for-the-true-case;
}
Else {
Statement(s)-for-the-false-caase;
}
3. Nested if statement
4. Multi-way if-else statement
5. Switch statement
6. Conditional expression
Syntax and Element:
1. Word: if
2. Parentheses
3. Condition or Boolean expression
4. Curly braces
5. Statement
Code example:
If (radius >= 0) {
Area = radius*radius*PI;
Listing 3.2
import java.util.Scanner;
if (number % 5 == 0)
if (number % 2 == 0)
Check Point
import java.util.Scanner;
int x;
if ( y > 0 )
x = 1;
import java.util.Scanner;
Two-Way If-Else
if ( )
import java.util.Scanner;
System.out.println(" Overwerght");
else
CHAPTER 5: LOOPS
5.1 Intro
- Loop means executed statement repeatedly
Code Example 1:
int count = 0;
Code Example 2:
int sum = 0, i = 1;
sum = sum + i;
i++;
1. While loop
2. do-while loop
3. for loop
While (loop-continuation-condition) {
// Loop body
Statement(s);
}
loop-
continuation-
condition
False
Statement(s)
(loop body)
True