WELCOME TO RICHFIELD
HYBRID LEARNING
MODULE: PROGRAMMING 631/731 (Java)
TOPIC 2:OPERATORS AND CONTROL STRUCTURES
[ADD PRESENTATION TITLE IN SLIDE MASTER MODE] | 1
Learning Outcomes:
After studying this topic you should be able to:
Arrays are objects that help us organize large amounts of information
Topic 2 focuses on:
‒ Use the increment and decrement operators.
‒ Use standard math methods.
‒ Use if and if-else statements to make choices.
‒ Use while and for loops to repeat a process.
‒ Construct appropriate conditions for control statements using relational operators.
‒ Detect and correct common loop errors.
[ADD PRESENTATION TITLE IN SLIDE MASTER MODE] | 2
Additional Operators
• Extended assignment operators
‒ Assignment operator combined with arithmetic
and concatenation operators
3 [ADD PRESENTATION TITLE IN SLIDE MASTER MODE] | 3 Fundamentals of Java
Additional Operators (cont.)
• Increment operator: ++
‒ Increase value of operand by 1
• Decrement operator: --
‒ Decrease value of operand by 1
4 [ADD PRESENTATION TITLE IN SLIDE MASTER MODE] | 4 Fundamentals of Java
Standard Classes and Methods: The Math Class
Table 1: Seven methods in the Math class
5 [ADD PRESENTATION TITLE IN SLIDE MASTER MODE] | 5
Fundamentals of Java
Standard Classes and Methods: The Math Class
(cont.)
• The two abs() methods are overloaded.
‒ Overloaded: Multiple methods in the same class
with the same name
• Using sqrt() method example:
6 [ADD PRESENTATION TITLE IN SLIDE MASTER MODE] | 6 Fundamentals of Java
Standard Classes and Methods: The Math Class
(cont.)
Math class methods example:
7 [ADD PRESENTATION TITLE IN SLIDE MASTER MODE] | 7
Fundamentals of Java
Standard Classes and Methods: The Random Class
• Random number generator: Returns numbers chosen at random from a pre-designated
interval
Table 2: Methods in the Random class
8 [ADD PRESENTATION TITLE IN SLIDE MASTER MODE] | 8 Fundamentals of Java
The if and if-else Statements
• Principal forms:
9 [ADD PRESENTATION TITLE IN SLIDE MASTER MODE] | 9 Fundamentals of Java
The if and if-else Statements (cont.)
• Examples of if statements:
10 [ADD PRESENTATION TITLE IN SLIDE MASTER MODE] | 10 Fundamentals of Java
The if and if-else Statements (cont.)
Table 4-3: Relational operators
11 [ADD PRESENTATION TITLE IN SLIDE MASTER MODE] | 11
Fundamentals of Java
The if and if-else Statements (cont.): Checking
Input for Validity
Example 4.1: Computes the area of a circle if the
radius >= 0 or otherwise displays an error message
12 [ADD PRESENTATION TITLE IN SLIDE MASTER MODE] | 12
Fundamentals of Java
THANK YOU
[ADD PRESENTATION TITLE IN SLIDE MASTER MODE] | 13