0% found this document useful (0 votes)
7 views

JAVA-Conditional-Statements

The document explains various Java conditional statements, including if, if-else, if-else if-else, and nested conditional statements, along with their syntax and examples. It also covers the use of logical operators within conditional statements. Additionally, it presents an activity for creating a program to compute and categorize average grades based on specified criteria.

Uploaded by

chescamheyreyes
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

JAVA-Conditional-Statements

The document explains various Java conditional statements, including if, if-else, if-else if-else, and nested conditional statements, along with their syntax and examples. It also covers the use of logical operators within conditional statements. Additionally, it presents an activity for creating a program to compute and categorize average grades based on specified criteria.

Uploaded by

chescamheyreyes
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

JAVA CONDITIONAL

STATEMENTS
CONDITIONAL STATEMENTS

Typically, it compares two values so that


our program can decide what action
should be taken
IF STATEMENT
Handles 1 conditional expression, it’s either does something or
nothing.
If Statement Syntax:
If(condition){
//Condition values
}
Example:
Int age = 10;
If(age == 10){
System.out.print(“You are now 10 years old”);
}
Output: You are now 10 years old
IF – ELSE STATEMENT
Handles 2 conditional expression, it either does the first code block or the second code
block.
If – Else Syntax:
if(condition){
//conditional value 1
}else{
//condition value 2
}
Example:
int age = 11;
if(age == 10 ){
System.out.print(“Your age is 10 years old”);
}else {
System.out.print(“Your age is not 10 years old”);
}
Output: Your age is not 10 years old
IF – ELSE IF - ELSE
Handles 3 or more conditional expressions, the possibility of this statement
are limitless it will run a certain block based on the condition
IF-ELSE IF-ELSE Syntax:
if(Condition 1){
//condition 1 value
}else if(condition 2){
//condition 2 value
}else{
//last condition
}
Example:
Int age = 10;
if(age >= 18){
System.out.println(“You have access”);
}else if(age >= 13){
System.out.println(“You need a parental consent to
access”);
}else{
System.out.println(“Access Denied!”);
}
Output: You have access
NESTED CONDITIONAL STATEMENT
A conditional statement within a conditional statement.
Nested Conditional Syntax:
if(condition 1){
if(additional condition){
//additional condition value
}
}else if(condition 2){
//condition 2 value
}else{
//last condition
}
Example:
int age = 18;
String gender = “male”;
if (age >= 18){
if(gender == “female”){
System.out.println(“Please proceed to Womens Party”);
}else if(gender == “male”){
System.out.println(“Please proceed to Mens Party”);
}
}else{
System.out.println(“Access Denied! You are under age.”);
}
Output: Please proceed to Mens Party
CONDITIONAL STATEMENT WITH
LOGICAL OPERATOR
Int age = 18;
Boolean hasID = true;
if (age >= 18 && hasID){
System.out.print(“You can now enter!”);
}else if (age >=18 || hasID){
System.out.print(“You can now enter!”);
}else if(age >= 18 && !hasID){
System.out.print(“You can now enter!”);
}else{
System.out.print(“Access Denied!”);
}
Activity

Create a program that will let the user input a 4 grades in math, science,
English and PE. Then compute the 4 inputs to get the average and
display the average based on its value.
Refer to this value:
Above 100 – Invalid
91 to 99 – Cum Laude
81 to 90 – Suma Cum Laude
71 to 80 – With Honors
61 to 70 – Honors
60 below - Failed

You might also like