java &&, java ||, logical operator
Short Circuit Operators are quite similar to bitwise operators except for the following differences.
Case 1.
x&&y =>> y will be evaluated if and only if x is true.If x is false then y won't be evaluated.
Case 2.
x | | y =>> y will be evaluated if and only if x is false.If x is true then y
won't be evaluated.
int x=10 ,y =15;
if( ++x <10 & ++y > 15 )
{
x++;
}
else
{
y++;
}
System.out.println( x+".........."+y);
output is: 11 ......17
Example 2.
int x=10 ,y =15;
if( ++x <10 && ++y > 15 )
{
x++;
}
else
{
y++;
}
System.out.println( x+".........."+y);
output is : 11 ......16
Example 3.
int x=10 ,y =15;
if( ++x <10 | ++y > 15 )
{
x++;
}
else
{
y++;
}
System.out.println( x+".........."+y);
output is : 12 ......16
Example 4.
int x=10 ,y =15;
if( ++x <10 && ++y > 15 )
{
x++;
}
else
{
y++;
}
System.out.println( x+".........."+y);
output is : 12 ......16
Example 5. Choose the correct Option?
int x=10;
if(++x<10 && x/0 >10)
{
System.out.println( "Hello");
}
else
{
System.out.println( "Hi");
}
(a) Compile Time Error
(b)Runtime Exception / By Zero
(c)Hello
(d)Hi
Ans: Hi
Hint: If block's condition is false that is why the else block will be executed.
No comments:
Post a Comment
Be the first to comment!
Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.
Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
Regards,
JavaByChetan
Back To Home