0% found this document useful (0 votes)
2 views

Boolean Worksheet

The document contains a Boolean worksheet that includes a truth table for various Boolean expressions involving variables a and b. It also presents a series of assignments to a variable x based on the values of other Boolean variables and provides a code snippet with conditional statements to determine output based on integer comparisons. Additionally, it includes another truth table for the output of a conditional statement based on the values of 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 DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Boolean Worksheet

The document contains a Boolean worksheet that includes a truth table for various Boolean expressions involving variables a and b. It also presents a series of assignments to a variable x based on the values of other Boolean variables and provides a code snippet with conditional statements to determine output based on integer comparisons. Additionally, it includes another truth table for the output of a conditional statement based on the values of 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 DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

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;

Write what value gets stored by the boolean variable x


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

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:

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

You might also like