SlideShare uma empresa Scribd logo
1 de 38
Ayesha Sani
Lecturer GIS
GCUF
 Statements inside your source files are generally executed
from top to bottom, in the order that they appear.
 Control flow statements, however, break up the flow of
execution by employing decision making, looping, and
branching, enabling your program to conditionally execute
particular blocks of code.
1. Selection or decision-making statements (if, if-else,
switch)
2. Looping statements (while, do-while, for)
3. Branching statements (break, continue, return)
Introduction – Control
Statements
Selection or decision making
statements
(if, if-else, switch)
The if statement
executes a block of code
only if the specified
expression is true.
If the value is false, then
the if block is skipped
and execution continues
with the rest of the
program.
Selection or decision-making statements
(if-then, if-then-else, switch)
The if/else statement is
an extension of the if
statement. If the
statements in the if
statement fails, the
statements in the else
block are executed.
Selection or decision-making statements
(if-then, if-then-else, switch)
More Examples of
“if” and “if-else”
Basic Structure of “if” and “if/else”
if (booleanExpression) {
statement(s);
}
Example:
if ((i > 0) && (i > 10)) {
System.out.println("i is an " +
"integer between 0 and 10");
}
class IfElseDemo {
public static void main(String[] args) {
int testscore = 76;
char grade;
if (testscore >= 90) {
grade = 'A';
}
else if (testscore >= 80) {
grade = 'B';
}
else if (testscore >= 70) {
grade = 'C';
}
else if (testscore >= 60) {
grade = 'D';
}
else {
grade = 'F';
}
System.out.println("Grade = " + grade);
}
}
class IfElseDemo {
public static void main(String[] args) {
int testscore = 76;
char grade;
if (testscore >= 90) {
grade = 'A';
}
if (testscore >= 80) {
grade = 'B';
}
if (testscore >= 70) {
grade = 'C';
}
if (testscore >= 60) {
grade = 'D';
}
else {
grade = 'F';
}
System.out.println("Grade = " + grade);
}
}
Adding a semicolon at the end of an if clause is a
common mistake.
if (radius >= 0);
{
area = radius*radius*PI;
System.out.println(
"The area for the circle of radius " +
radius + " is " + area);
}
This mistake is hard to find, because it is not a
compilation error or a runtime error, it is a logic error.
This error often occurs when you use the next-line
block style.
Wrong
if (radius >= 0) {
area = radius*radius*PI;
System.out.println("The area for the “
+ “circle of radius " + radius +
" is " + area);
}
else {
System.out.println("Negative input");
}
The else clause matches the most recent if clause in the
same block. For example, the following statement
int i = 1; int j = 2; int k = 3;
if (i > j)
if (i > k)
System.out.println("A");
else
System.out.println("B");
is equivalent to
int i = 1; int j = 2; int k = 3;
if (i > j)
{
if (i > k)
System.out.println("A");
else
System.out.println("B");
}
Or Change it to
int i = 1; int j = 2; int k = 3;
if (i > j)
{
if (i > k)
System.out.println("A");
}
else
{
System.out.println("B");
}
Nothing is printed as Output
B is printed as Output
Summary Switch
 The keyword "switch"
is followed by an expression
that should evaluates to byte,
short, char or int primitive data
types ,only.
 In a switch block there can
be one or more labeled cases
and the expression that creates
labels for the case must be
unique.
The switch expression is
matched with each case label.
Only the matched case is
executed ,if no case matches
then the default statement (if
present) is executed.
The case statements are executed in sequential
order.)
The keyword break is optional, but it should be used
at the end of each case in order to terminate the
remainder of the switch statement. If the break
statement is not present, the next case statement
will be executed.
The default case, which is optional, can be used to
perform actions when none of the specified cases is
true
Looping Statements
(for, while, do-while)
The while statement continually
executes a block of statements
while a particular condition is true.
Its syntax can be expressed as:
while (expression) {
statement(s)
}
“while” loops
The Java programming language also provides a do-
while statement, which can be expressed as follows:
do {
statement(s)
} while (expression) ;
“do while” loops
Important
You can implement an infinite loop using the
while statement as follows:
while (true){
// your code goes here
}
Examples
“for” loop
The for statement provides a compact way to iterate
over a range of values
The general form of the “for” statement can be
expressed as follows:
for (initialization; termination; increment) {
statement(s)
}
for (int i=1; i<11; i++) {
System.out.println("Count is: " + i);
}
for loop Example
for (int i=1; i<=10; i++)
{
if (i%2==0){
System.out.println(i+“ is an even number”) ;
}
else{
System.out.println(i+“ is a odd number”) ;
}
}
Branching Statements
(break, continue)
Branching statements
(break, continue)
The break statement is used for breaking the
execution of a loop (while, do-while and for) . It
also terminates the switch statements.
// yourNumber contains an integer input by the user using
// JOptionPane.showInput Dialog
int yourNumber ;
for (i = 0; i < 10; i++) {
if (yourNumber== i) {
break;
}
System.out.println(“Number = ” + i);
}
Branching statements
(break, continue)
The continue statement is used to skip that
specific execution of a loop (while, do-while and
for) .
// yourNumber contains an integer input by the user using
// JOptionPane.showInput Dialog
int yourNumber ;
for (i = 0; i < 10; i++) {
if (yourNumber== i) {
continue;
}
System.out.println(“Number = ” + i);
}
 Statements inside your source files are generally executed
from top to bottom, in the order that they appear.
 Control flow statements, however, break up the flow of
execution by employing decision making, looping, and
branching, enabling your program to conditionally execute
particular blocks of code.
1. Selection or decision-making statements (if, if-else,
switch)
2. looping statements (for, while, do-while)
3. branching statements (break, continue, return)
Summary – Control Statements
Steps of Writing a Java Program
1. Pseudo Code
2. Flow Chart
3. Write Program
4. Run
5. Debug
Algorithm Building
 Write a program that takes an integer input
from user and print the table of that
number upto 10. (Print the table only if the
input number is between 3 and 20) [Note:
Use for loop]
 Write a program that calculates the product
of the odd integers from 1 to 15, then
displays the results in a message dialog
[Note: Use for loop]
Exercise 1
 Body Mass Index Program
 Print 1 2 3 4 5 4 3 2 1 using a single for
loop
 Change the Cricket program so that all the
input is done in a single loop
 Mobile Bill Calculation Software
Exercise 2
1 pound = 0.453 592 37 kilogram
Use loops (for or while) to generate the following
patterns
*
* *
* * *
* * * *
* * * * *
*
**
***
****
***** *
* *
* * *
* * * *
* * * * *
* * * * *
* * * *
* * *
* *
*
 Write such a Java program that takes integer
numbers input from the user (between 0
and 100) and print the number in English
letters.
Example:
 Input number 8 - Ouput = “Eight”
 Input number 39 - Ouput = “Thirty Nine”
 Input number 61 - Ouput = “Sixty One”
 Hint: Use % (Remainder Operator) with if
Control statement to program this task.

Mais conteúdo relacionado

Mais procurados

Control Structures
Control StructuresControl Structures
Control Structures
Ghaffar Khan
 
Automated Repair of Feature Interaction Failures in Automated Driving Systems
Automated Repair of Feature Interaction Failures in Automated Driving SystemsAutomated Repair of Feature Interaction Failures in Automated Driving Systems
Automated Repair of Feature Interaction Failures in Automated Driving Systems
Lionel Briand
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual Basic
Tushar Jain
 
Control structures in Java
Control structures in JavaControl structures in Java
Control structures in Java
Ravi_Kant_Sahu
 

Mais procurados (20)

M C6java5
M C6java5M C6java5
M C6java5
 
Control structures i
Control structures i Control structures i
Control structures i
 
07 flow control
07   flow control07   flow control
07 flow control
 
Control statements in java programmng
Control statements in java programmngControl statements in java programmng
Control statements in java programmng
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Ch02 primitive-data-definite-loops
Ch02 primitive-data-definite-loopsCh02 primitive-data-definite-loops
Ch02 primitive-data-definite-loops
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
 
Control Structures
Control StructuresControl Structures
Control Structures
 
Control Structures: Part 1
Control Structures: Part 1Control Structures: Part 1
Control Structures: Part 1
 
Control statements
Control statementsControl statements
Control statements
 
Automated Repair of Feature Interaction Failures in Automated Driving Systems
Automated Repair of Feature Interaction Failures in Automated Driving SystemsAutomated Repair of Feature Interaction Failures in Automated Driving Systems
Automated Repair of Feature Interaction Failures in Automated Driving Systems
 
130707833146508191
130707833146508191130707833146508191
130707833146508191
 
Std 12 Computer Chapter 7 Java Basics (Part 2)
Std 12 Computer Chapter 7 Java Basics (Part 2)Std 12 Computer Chapter 7 Java Basics (Part 2)
Std 12 Computer Chapter 7 Java Basics (Part 2)
 
Std 12 computer java basics part 3 control structure
Std 12 computer java basics part 3 control structureStd 12 computer java basics part 3 control structure
Std 12 computer java basics part 3 control structure
 
Control statement-Selective
Control statement-SelectiveControl statement-Selective
Control statement-Selective
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual Basic
 
C# Loops
C# LoopsC# Loops
C# Loops
 
Control structures in Java
Control structures in JavaControl structures in Java
Control structures in Java
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selection
 

Semelhante a control statements

Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
ChaAstillas
 
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
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
jahanullah
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java Programming
Pathomchon Sriwilairit
 

Semelhante a control statements (20)

Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)
 
Lecture - 5 Control Statement
Lecture - 5 Control StatementLecture - 5 Control Statement
Lecture - 5 Control Statement
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Loops
LoopsLoops
Loops
 
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
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
 
Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structures
 
Loops c++
Loops c++Loops c++
Loops c++
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
Oop object oriented programing topics
Oop object oriented programing topicsOop object oriented programing topics
Oop object oriented programing topics
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java Programming
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Java tutorial PPT
Java tutorial  PPTJava tutorial  PPT
Java tutorial PPT
 
Chap05
Chap05Chap05
Chap05
 
Ch05
Ch05Ch05
Ch05
 

Último

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

control statements

  • 2.  Statements inside your source files are generally executed from top to bottom, in the order that they appear.  Control flow statements, however, break up the flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code. 1. Selection or decision-making statements (if, if-else, switch) 2. Looping statements (while, do-while, for) 3. Branching statements (break, continue, return) Introduction – Control Statements
  • 3. Selection or decision making statements (if, if-else, switch)
  • 4. The if statement executes a block of code only if the specified expression is true. If the value is false, then the if block is skipped and execution continues with the rest of the program. Selection or decision-making statements (if-then, if-then-else, switch)
  • 5. The if/else statement is an extension of the if statement. If the statements in the if statement fails, the statements in the else block are executed. Selection or decision-making statements (if-then, if-then-else, switch)
  • 6. More Examples of “if” and “if-else”
  • 7. Basic Structure of “if” and “if/else”
  • 8. if (booleanExpression) { statement(s); } Example: if ((i > 0) && (i > 10)) { System.out.println("i is an " + "integer between 0 and 10"); }
  • 9.
  • 10. class IfElseDemo { public static void main(String[] args) { int testscore = 76; char grade; if (testscore >= 90) { grade = 'A'; } else if (testscore >= 80) { grade = 'B'; } else if (testscore >= 70) { grade = 'C'; } else if (testscore >= 60) { grade = 'D'; } else { grade = 'F'; } System.out.println("Grade = " + grade); } } class IfElseDemo { public static void main(String[] args) { int testscore = 76; char grade; if (testscore >= 90) { grade = 'A'; } if (testscore >= 80) { grade = 'B'; } if (testscore >= 70) { grade = 'C'; } if (testscore >= 60) { grade = 'D'; } else { grade = 'F'; } System.out.println("Grade = " + grade); } }
  • 11. Adding a semicolon at the end of an if clause is a common mistake. if (radius >= 0); { area = radius*radius*PI; System.out.println( "The area for the circle of radius " + radius + " is " + area); } This mistake is hard to find, because it is not a compilation error or a runtime error, it is a logic error. This error often occurs when you use the next-line block style. Wrong
  • 12. if (radius >= 0) { area = radius*radius*PI; System.out.println("The area for the “ + “circle of radius " + radius + " is " + area); } else { System.out.println("Negative input"); }
  • 13. The else clause matches the most recent if clause in the same block. For example, the following statement int i = 1; int j = 2; int k = 3; if (i > j) if (i > k) System.out.println("A"); else System.out.println("B"); is equivalent to int i = 1; int j = 2; int k = 3; if (i > j) { if (i > k) System.out.println("A"); else System.out.println("B"); } Or Change it to int i = 1; int j = 2; int k = 3; if (i > j) { if (i > k) System.out.println("A"); } else { System.out.println("B"); } Nothing is printed as Output B is printed as Output
  • 14.
  • 15. Summary Switch  The keyword "switch" is followed by an expression that should evaluates to byte, short, char or int primitive data types ,only.  In a switch block there can be one or more labeled cases and the expression that creates labels for the case must be unique. The switch expression is matched with each case label. Only the matched case is executed ,if no case matches then the default statement (if present) is executed.
  • 16. The case statements are executed in sequential order.) The keyword break is optional, but it should be used at the end of each case in order to terminate the remainder of the switch statement. If the break statement is not present, the next case statement will be executed. The default case, which is optional, can be used to perform actions when none of the specified cases is true
  • 17.
  • 19. The while statement continually executes a block of statements while a particular condition is true. Its syntax can be expressed as: while (expression) { statement(s) } “while” loops
  • 20. The Java programming language also provides a do- while statement, which can be expressed as follows: do { statement(s) } while (expression) ; “do while” loops
  • 21. Important You can implement an infinite loop using the while statement as follows: while (true){ // your code goes here }
  • 23. “for” loop The for statement provides a compact way to iterate over a range of values The general form of the “for” statement can be expressed as follows: for (initialization; termination; increment) { statement(s) } for (int i=1; i<11; i++) { System.out.println("Count is: " + i); }
  • 24. for loop Example for (int i=1; i<=10; i++) { if (i%2==0){ System.out.println(i+“ is an even number”) ; } else{ System.out.println(i+“ is a odd number”) ; } }
  • 26. Branching statements (break, continue) The break statement is used for breaking the execution of a loop (while, do-while and for) . It also terminates the switch statements. // yourNumber contains an integer input by the user using // JOptionPane.showInput Dialog int yourNumber ; for (i = 0; i < 10; i++) { if (yourNumber== i) { break; } System.out.println(“Number = ” + i); }
  • 27. Branching statements (break, continue) The continue statement is used to skip that specific execution of a loop (while, do-while and for) . // yourNumber contains an integer input by the user using // JOptionPane.showInput Dialog int yourNumber ; for (i = 0; i < 10; i++) { if (yourNumber== i) { continue; } System.out.println(“Number = ” + i); }
  • 28.  Statements inside your source files are generally executed from top to bottom, in the order that they appear.  Control flow statements, however, break up the flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code. 1. Selection or decision-making statements (if, if-else, switch) 2. looping statements (for, while, do-while) 3. branching statements (break, continue, return) Summary – Control Statements
  • 29. Steps of Writing a Java Program 1. Pseudo Code 2. Flow Chart 3. Write Program 4. Run 5. Debug Algorithm Building
  • 30.
  • 31.  Write a program that takes an integer input from user and print the table of that number upto 10. (Print the table only if the input number is between 3 and 20) [Note: Use for loop]  Write a program that calculates the product of the odd integers from 1 to 15, then displays the results in a message dialog [Note: Use for loop] Exercise 1
  • 32.  Body Mass Index Program  Print 1 2 3 4 5 4 3 2 1 using a single for loop  Change the Cricket program so that all the input is done in a single loop  Mobile Bill Calculation Software Exercise 2
  • 33. 1 pound = 0.453 592 37 kilogram
  • 34.
  • 35.
  • 36. Use loops (for or while) to generate the following patterns * * * * * * * * * * * * * * * * ** *** **** ***** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  • 37.
  • 38.  Write such a Java program that takes integer numbers input from the user (between 0 and 100) and print the number in English letters. Example:  Input number 8 - Ouput = “Eight”  Input number 39 - Ouput = “Thirty Nine”  Input number 61 - Ouput = “Sixty One”  Hint: Use % (Remainder Operator) with if Control statement to program this task.