Boolean Worksheet
Boolean Worksheet
Fill in the following truth table using the following boolean variables assuming they have
been declared.
boolean a;
boolean b;
// use a and b as defined below in the truth table
boolean c=a&&b;
boolean d=(a&&b)&&(a||b);
boolean e= a==b;
boolean f= (b!=a) || (a==b);
boolean g= !a;
boolean h=!a && b;
boolean i= !(a&&b);
boolean j= (a&&b)||(a==b);
a b c d e f g h i j
true true
true false
false true
false false
boolean a=true;
boolean b=false;
boolean c=true;
boolean d=true;
2. x=(!a||b)&&(c||d);
3. x=!(a||b)&&(c||d);
4. x=!true;
5. x=a||b||c||d;
6. x=(a||b)&&c;
What is the output for the below code?
int x=5;
int y=7;
int z=5;
boolean first=true;
boolean last= false;
if(x==z)
last=true;
else
System.out.println(“one”);
if(y>z){
if(first==last)
System.out.println(“two”);
else
y++;
}
else
x++;
if(x==y)
System.out.println(“three”);
else
System.out.println (“four”);
Answer: