0% found this document useful (0 votes)
3 views14 pages

Module 3-Sequencial Structure

The document provides an overview of Java's control structures, focusing on sequential, conditional, and iteration structures. It explains sequential control as line-by-line execution and details various conditional statements such as if...else, if...else...if, and nested if...else statements with examples. The examples illustrate how to implement these structures in Java to determine conditions and outcomes based on variable values.

Uploaded by

Jay Abaleta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views14 pages

Module 3-Sequencial Structure

The document provides an overview of Java's control structures, focusing on sequential, conditional, and iteration structures. It explains sequential control as line-by-line execution and details various conditional statements such as if...else, if...else...if, and nested if...else statements with examples. The examples illustrate how to implement these structures in Java to determine conditions and outcomes based on variable values.

Uploaded by

Jay Abaleta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

JAVA Sequential, Conditional

and Iteration Structure

Lecturer: Jay A. Abaleta


What is Sequential Control Structure?

• It Refers to Line by Line Execution which statement


executed sequentially
• The basic mechanism of Java is the sequential structure.
Unless otherwise specified, it will be executed sentence
by sentence in order;

• Sequential structure is the simplest algorithm structure;


Example
Conditional Control Structures
Java if...else Statement
Java if...else Statement
Java if...else Statement Example
public class IfelseStatement
{
public static void main(String[] args)
{
int number = 3;
// checks if number is less than 0
if (number > 0) {
System.out.println("The number is Positive.");
}
else
{
System.out.println(“The number is Negative");
}
}
Java if...else...if Statement
Java if...else...if Statement
Java if...else...if Statement
Java if...else...if Statement Example
public class Main {
public static void main(String[] args) {
int number = 0;
// checks if number is greater than 0
if (number > 0) {
System.out.println("The number is positive.");
}
// checks if number is less than 0
else if (number < 0) {
System.out.println("The number is negative.");
}
// if both condition is false
else {
System.out.println("The number is 0.");
}
}
}
Java Nested if..else Statement
 In Java, it is also possible to use if..else statements inside an if...else
statement. It's called the nested if...else statement.
 Syntax

The syntax for a nested if...else is as follows −

if(Boolean_expression 1) {
// Executes when the Boolean expression 1 is true
if(Boolean_expression 2) {
// Executes when the Boolean expression 2 is true
}
}
Java Nested if..else Statement Example
public class Main {
public static void main(String[] args) {

// declaring double type variables


Double n1 = -1.0, n2 = 4.5, n3 = -5.3, largest;

// checks if n1 is greater than or equal to n2


if (n1 >= n2) {

// if...else statement inside the if block


// checks if n1 is greater than or equal to n3
if (n1 >= n3) {
largest = n1;
}
Java Nested if..else Statement Example
else {
largest = n3;
}
} else {
// if..else statement inside else block
// checks if n2 is greater than or equal to n3
if (n2 >= n3) {
largest = n2;
}
else {
largest = n3;
}
}
System.out.println("Largest Number: " + largest);
}
}

You might also like