In: Computer Science
Write a Java program that defines two boolean variables a and b and shows that regardless of the values of a and b, the expressions (a && (a || b)) and a are always the same.
public class logic
{
   public static void main(String args[])
   {
       boolean a = true;
       boolean b = true;
       System.out.println("Value of a now:
"+a);
       System.out.println("Value of b now:
"+b);
       System.out.println((a
&&(a||b)));
       a = true;
       b = false;
       System.out.println("Value of a now:
"+a);
       System.out.println("Value of b now:
"+b);
       System.out.println((a
&&(a||b)));
       a = false;
       b = true;
       System.out.println("Value of a now:
"+a);
       System.out.println("Value of b now:
"+b);
       System.out.println((a
&&(a||b)));
       a = false;
       b = false;
       System.out.println("Value of a now:
"+a);
       System.out.println("Value of b now:
"+b);
       System.out.println((a
&&(a||b)));
   }
}

//The above is the screen shot to refer to the indentation.

//The above is the output of the above code.
// you can see clearly from the output that value of the expression always equal to that of the value of a.
// Here we have tried all possible combination with 2 variable i.e 4 combinations as you can see.
// Please rate the solution and ask your doubts if any in the comments section below.