If You Have To Check Two Variable Values To Given Two Values, You May Some Time Write Many If Else Statements To Check For Many Variable Values.Without Writing Many If Else Statement You Can Check Many Values That Mean Many If Else Statements In A Single Statement By Using AND or OR Logical Operators.
You Can Use AND(&&) Logical Operator If You Want To Do Something After Every Operator Gets True.
You Can Use OR(||) Logical Operator If You Want To Do Something After Any Of The Operator Gets True.
Following Example Demonstrate How AND , OR Operators Work.
class EasyCodeStuff {
public static void main(String args[]){
int No1 = 10;
int No2 = 20;
//AND Logical Opearator
if (No1 == 10 && No1 == 20){
System.out.println("No1 is Equal To 10 AND No2 is Equal To 20");
}else{
System.out.print("No1 is Not Equal To 10 OR No2 is Not Equal To 20");
}
//OR Logical Operator
if (No1 == 10 || No1 == 20){
System.out.println("No1 is Equal To 10 OR No2 is Equal To 20");
}else{
System.out.print("No1 is Not Equal To 10 AND No2 is Not Equal To 20");
}
}
}
Showing posts with label If. Show all posts
Showing posts with label If. Show all posts
Jul 17, 2014
If Else In Java With ( == , != , < , > , <= , >= Opearators)
In This Example I'm Trying To Explain How If Else Statements Work In Java.
You can Check many Logical Operators With If Else Statements.
There Are Mainly 6 Types.
1. Equal ==
2. Not Equal !=
3. Less Than <
4. Greater Than >
5. Less Than Or Equal <=
6. Greater Than Or Equal >=
Following Example Shows Use Of Operators With if Else Statements
class EasyCodeStuff {
public static void main(String args[]){
int No1 = 10;
//Equal Opeartion
if (No1 == 10){
System.out.println("No1 is Equal To 10");
}else{
System.out.print("No1 is Not Equal To 10");
}
//Not Equal Opeartion
if (No1 != 10){
System.out.println("No1 is Not Equal To 10");
}else{
System.out.println("No1 is Equal To 10");
}
//Less Than Opeartion
if (No1 < 10){
System.out.println("No1 is Less Than 10");
}else{
System.out.println("No1 is Not Less Than 10");
}
//Greater Than Opeartion
if (No1 > 10){
System.out.println("No1 is Greater Than 10");
}else{
System.out.println("No1 is Not Greater Than 10");
}
//Less Than Or Equal Opeartion
if (No1 <= 10){
System.out.println("No1 is Less Than Or Equal To 10");
}else{
System.out.println("No1 is Not Less Than 10");
}
//Greater Than Or Equal Opeartion
if (No1 >= 10){
System.out.println("No1 is Greater Than Or Equal To 10");
}else{
System.out.println("No1 is Not Greater Than 10");
}
}
}
You can Check many Logical Operators With If Else Statements.
There Are Mainly 6 Types.
1. Equal ==
2. Not Equal !=
3. Less Than <
4. Greater Than >
5. Less Than Or Equal <=
6. Greater Than Or Equal >=
Following Example Shows Use Of Operators With if Else Statements
class EasyCodeStuff {
public static void main(String args[]){
int No1 = 10;
//Equal Opeartion
if (No1 == 10){
System.out.println("No1 is Equal To 10");
}else{
System.out.print("No1 is Not Equal To 10");
}
//Not Equal Opeartion
if (No1 != 10){
System.out.println("No1 is Not Equal To 10");
}else{
System.out.println("No1 is Equal To 10");
}
//Less Than Opeartion
if (No1 < 10){
System.out.println("No1 is Less Than 10");
}else{
System.out.println("No1 is Not Less Than 10");
}
//Greater Than Opeartion
if (No1 > 10){
System.out.println("No1 is Greater Than 10");
}else{
System.out.println("No1 is Not Greater Than 10");
}
//Less Than Or Equal Opeartion
if (No1 <= 10){
System.out.println("No1 is Less Than Or Equal To 10");
}else{
System.out.println("No1 is Not Less Than 10");
}
//Greater Than Or Equal Opeartion
if (No1 >= 10){
System.out.println("No1 is Greater Than Or Equal To 10");
}else{
System.out.println("No1 is Not Greater Than 10");
}
}
}
Subscribe to:
Posts (Atom)
JWT Token Decode Using Jquery
When it come to authentication we use many mechanism. Ones the user authenticated we must keep these details somewhere safe. So we can share...
-
In this blog post Ill explain you the logic behind the Sri Lankan National Identity Card (NIC). Sri Lanka now has Old NIC No Format as well ...
-
In This Article I Will Demonstrate You To Create A Simple Chat Program Using Java Remote Method Invocation(RMI). Following Program Supports ...
-
In a windows form application sometimes you may want to import a excel file to a data grid view. In this blog post Ill demonstrate to you gu...