0% found this document useful (0 votes)
12 views5 pages

AP CSA Quiz REVIEW Conditional Statements and Boolean Expressions

Ap computer science a review quiz 2

Uploaded by

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

AP CSA Quiz REVIEW Conditional Statements and Boolean Expressions

Ap computer science a review quiz 2

Uploaded by

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

AP CSA Name: ___________________

Condi&onal Statements/Boolean Expressions - Review


1) Using DeMorgan’s Law, write an equivalent expression for !(x > 9 || y == 1)

2) What is the value of x aEer the following code segment runs?

int x = 22;
if(x < 14)
{
x *= 3;
}
else if(x < 32)
{
x -= 12;
}
if(x < 80)
{
x *= 4;
}

3) What are the correct output values for x if we test the input values of x = 42, 14, 1?

if(x >= 32)


{
x = 80;
}
else if(x >= 12)
{
x = -9;
}
else
{
x += 5;
}
4) What will the following print when x = 42 and y = 37?

if (!(y > 432 && x < 389))


{
System.out.print("Java");
}
else
{
System.out.print("Python");
}

System.out.println(" Coding is Best!");

5) What will the following print?

Int a = 43;
Int b = 58;

If(a > 35)


{
a += 100;
}

If(b > 45)


{
b -= 100;
}

If(a > 55)


{
System.out.print(“Sleep “);
}

else if(b < 85)


{
System.out.print(“is “);
}

System.out.print(“important“);
6) What will the following code RETURN?

int a = 4;
int b = 30;
if(a == 2 || b > 1)
{
return (a*b);
}
if(a > 3 && b != 3)
{
return (a+5);
}
if(a != 4 && b > 8)
{
return (a-b+2);
}

7) Which of the following is true aEer the code executes? Select ALL that apply

String a = new String(“Good”);


String b = new String(“Class”);
String c = new String(“Class”);
a = c;

a) a != b && a .equals(c);
b) a == c && a .equals(b);
c) a == b || b.equals(c);
d) a == c && a == b

8) What will the following code print out?

String w = “JokeBookWriter”;
int i = w.indexOf(“Book”);
if(i == -1)
{
System.out.print(w.length());
}
else
{
System.out.print(w.substring(i, i+3));
}
9) Consider the following variable declara[ons/ini[aliza[ons.

int x = 30;
int y = 72;
int z = 45;

Are the following true or false?

a) x < y && z > y


b) x > y || y < z
c) x < y != y < z

10) Analyze the code below:

String word = “Facebook”;

if(word.equals(“Amazon”))
{
System.out.println(“computer”);
}

else if(!word.equals(“Facebook”))
{
System.out.println(“science”);
}

else
{
System.out.println(“coding”);
}

What will be printed when the above code runs?


Answers:

1) x <= 9 && y != 1
2) x = 40
3) When input is 42, output is 80
When input is 14, output is -9
When input is 1, output is 6
4) Java Coding is Best!
5) Sleep important
6) 120
7) a, b, c
8) Boo
9) a is false
b is false
c is true
10) coding

You might also like