Java program to show use of logical operator

Java program to sho use of if else with logical operator.

  • And
  • OR
  • Not

AND

[java]
class IfWith_AND
{
public static void main(String args[]){

int x = 3;

if (x>5 && x>25)
{
System.out.println("Both of your conditions are true");
}
else
{
System.out.println("None of your conditions are true");
}
}
}
[/java]

OR

[java]
class IfWith_OR
{
public static void main(String args[]){

int x = 40;

if (x<3 || x>5)
{
System.out.println("One/Both of your conditions are true");
}
else
{
System.out.println("None of your conditions are true");
}
}
}
[/java]

NOT

[java]
class IfWith_NOT
{
public static void main(String args[]){

float x = Float.valueOf(args[0]);

if(!((x % 2) == 0))
{
System.out.println("ODD");
}
else
{
System.out.println("EVEN");
}
}
}
[/java]

Share

About the Author

Akash Padhiyar

Visit Website

There are no comments yet, add one below.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.