The document explains conditional statements in Java, which allow programs to execute code based on specified conditions. It covers relational operators, the use of if, else, else if, and switch statements for handling various conditions. Additionally, it includes exercises for practical application, such as determining voting eligibility and classifying student grades.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
11 views
Conditional Statement C#
The document explains conditional statements in Java, which allow programs to execute code based on specified conditions. It covers relational operators, the use of if, else, else if, and switch statements for handling various conditions. Additionally, it includes exercises for practical application, such as determining voting eligibility and classifying student grades.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11
Conditional
Statement(Java) Conditional Statements
Allows program to take action based on the given condition. It
makes our program smarter. Relational Operators LABEL SYMBOL SYNTAX Equals == x == y Not Equals != x !=y Less Than < x <y Less Than or Equals <= x <= y Greater Than > x>y Greater Than or >= x >=y Equals Conditional Statements
Java has the following conditional statements:
Use if to specify a block of code to be executed, if a specified
condition is true Use else to specify a block of code to be executed, if the same condition is false Use else if to specify a new condition to test, if the first condition is false Use switch to specify many alternative blocks of code to be executed The if Statement
Use the if statement to specify a block of Java code to be
executed if a condition is true. Handles 1 Condition Expression, it either does something or nothing.
If(condition){ //Do everything you want here { IF-ELSE Statement
Handles 2 condition expressions, it either does the first code
block or second code block If(condition){ //Do everything you want here }else{ //Do everything you want here } Exercise:
Write a C# Sharp program to read the age of a candidate and
determine whether it is eligible for casting his/her own vote. IF-ELSE IF-ELSE Statement
Handles 3 or more conditional expression, the possibility of this
statement are limitless it will run a certain code block based on the condition. If(condition) //Do everything you want here }else if(condition){ //Do everything you want here }else{ //Do everything you want here } Exercise:
1. Write a program that classify if student grade is pass, needs
more practice or fail.
2. Write a program that check if temperature is hot, warm or cold.