0% found this document useful (0 votes)
21 views11 pages

7 - Logical Expressions With If Statement

Here are the logical expressions for the given conditions: 1. n % 2 == 0 2. n > 0 3. n % 5 == 0 A. n > 0 && m > 0 && n <= m B. n % 5 == 0 && n % 10 != 0 C. n % 2 != 0 && n % 11 == 0

Uploaded by

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

7 - Logical Expressions With If Statement

Here are the logical expressions for the given conditions: 1. n % 2 == 0 2. n > 0 3. n % 5 == 0 A. n > 0 && m > 0 && n <= m B. n % 5 == 0 && n % 10 != 0 C. n % 2 != 0 && n % 11 == 0

Uploaded by

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

 The purpose a conditional construct in a

program is to enable a programmer to


execute specific statements based on a given
condition and write user-friendly code that
displays appropriate error messages for
appropriate situations in a program.
Students be able to
 understand the syntax of an if……else construct in
Java and be able to apply a Boolean expression
appropriately in it.
 apply the If….. else conditional construct
appropriately in a Java program and execute the
program
 evaluate a program that has an if…else construct in it
and trace the output of the code
 apply the if….elseif….else construct appropriately for
multiple conditions in a Java program
 execute a program using if…elseif….else
 evaluate a program that has an if…elseif….else
construct in it and trace the output of the code
• To understand the syntax of an if…else construct in Java and
be able to apply Boolean expressions appropriately in it.
• To generate a simple code using if… Else statement
• To evaluate a program that has if…else construct and trace
the output.
• To apply the if….elseif….else construct appropriately for
multiple conditions in a Java program
• To create programs using if…elseif…else
• To evaluate a program that has an if…elseif….else construct in
it and trace the output of the code
 List the logical operators in Java

 List the relational operators in Java

 What is the difference between = and the ==


operators?
 Logical expressions are a fundamental part
of the if statement and are formed using the
following operators:

◦ Relational operators
◦ Logical operators

 A Logical expression results into either a


false or true value.
 Constants
 Variables
 Expressions that contain arithmetic operators

 Examples:
 if(x>=y)
 if(x!=y)
 if(x==y)
 if(x+10)>y
 The operands of the logical operators can be
boolean variables or relational expressions
that contain relational operators.
 Examples:
◦ if(cnt != x+y && m/n>x*y)
◦ if ( x % 7 == 0 || x % 3==0)
 Logical && - Produces TRUE only when
_________the relational expressions are TRUE.

 Logical || - Produces TRUE if ______________


the relational expression is TRUE.

 Logical ! – Toggles(changes) ________ to


______ and ______ to ________.
1. Check if a number is an even number
2. Check if a number is a positive number
3. Check if a number is divisible by 5
--------------------------------------
A. Check if n and m are positive integers and n
is less than or equal to m
B. Check if the number is divisible by 5 and
not by 10
C. Check if a number is an odd number and is
divisible by 11

You might also like