WHAT IS SHORT CIRCUIT OPERATOR IN JAVA

jayprakash sharma

Total Post:117

Points:821
Posted by  jayprakash sharma
Java  OOPS 
 1179  View(s)
Ratings:
Rate this:
example of short circuit operator
  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: what is short circuit operator in java

    The OR operator results in true when one operand is true, no matter what the second operand is.
    The AND operator results in false when one operand is false, no matter what the second operand is.
    If you use the || and &&, Java will not evaluate the right-hand operand when the outcome can be determined by the left operand alone.
    The following code shows how you can use short-circuit logical operator to ensure that a division operation will be valid before evaluating it:

    class Program

    {

        static void Main(string[] args)

        {

                int x = 0;

                int y = 0;

                for(int i=0;i<10;i++)

                {

                    if (x++ < 7 || y++ < 5) ;

                }

                System.out.println(x);

                System.out.println(y);

        }

    }

      Modified On Oct-03-2014 11:49:23 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!