Featured Posts
Recent Articles

Sample Code that use Conditional Operators in Java

The && and || operators perform Conditional-AND and Conditional-OR operations on two boolean expressions. These operators exhibit "short-circuiting" behavior, which means that the second operand is evaluated only if needed.

&& Conditional-AND
|| Conditional-OR

class ConditionalDemo1 {

public static void main(String[] args){
int value1 = 1;
int value2 = 2;
if((value1 == 1) && (value2 == 2)) System.out.println("value1 is 1 AND value2 is 2");
if((value1 == 1) || (value2 == 1)) System.out.println("value1 is 1 OR value2 is 1");


}
}

class ConditionalDemo2 {

public static void main(String[] args){
int value1 = 1;
int value2 = 2;
int result;
boolean someCondition = true;
result = someCondition ? value1 : value2;

System.out.println(result);

}
}

Share and Enjoy:

0 comments for this post

Leave a reply

We will keep You Updated...
Sign up to receive breaking news
as well as receive other site updates!
Subscribe via RSS Feed subscribe to feeds
Recent Stories
Blog Archives
Recent Comments
Tag Cloud