0% found this document useful (0 votes)
14 views3 pages

Boolean Worksheet-1

The document contains a Boolean worksheet that includes a truth table for various boolean expressions involving variables a and b. It also provides a series of boolean operations and their resulting values, followed by a code snippet with conditional statements and its output. Finally, it includes another truth table for the output of a conditional statement based on boolean variables a and b.

Uploaded by

brockvincik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Boolean Worksheet-1

The document contains a Boolean worksheet that includes a truth table for various boolean expressions involving variables a and b. It also provides a series of boolean operations and their resulting values, followed by a code snippet with conditional statements and its output. Finally, it includes another truth table for the output of a conditional statement based on boolean variables a and b.

Uploaded by

brockvincik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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 true true false false false false true

true false false false false true false false true false

false true false false false true true true true false

false false false false false True true true true false

boolean a=true;
boolean b=false;
boolean c=true;
boolean d=true;

Write what value gets stored by the boolean variable x


boolean x;
1. x=(a&&b)||(c&&d); \(x = (true && false) || (false && false)\) \(x = false || false\)
x = false

2. x=(!a||b)&&(c||d); $x = (!true || false) && (false || false)$$x = (false || false) &&


false$ \(x = false && false\) x = false

3. x=!(a||b)&&(c||d); $x = !(true || false) && (false || false) $\(x = !true && false\) \
(x = false && false\) x = false

4. x=!true; x = false

5. x=a||b||c||d; \(x = true || false || false || false\) x = true


6. x=(a||b)&&c; $x = (true || false) && false$ \(x = true && false\) x = false

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:
four

//Fill in the truth table


//Assume a and b are defined boolean variables
if(a&&b)
System.out.println(“yes”);
else
System.out.println(“no”);
A B Output
true false no
true true yes
false true no
false false yes

You might also like