AP CSA Quiz REVIEW Conditional Statements and Boolean Expressions
AP CSA Quiz REVIEW Conditional Statements and Boolean Expressions
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?
Int a = 43;
Int b = 58;
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
a) a != b && a .equals(c);
b) a == c && a .equals(b);
c) a == b || b.equals(c);
d) a == c && a == b
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;
if(word.equals(“Amazon”))
{
System.out.println(“computer”);
}
else if(!word.equals(“Facebook”))
{
System.out.println(“science”);
}
else
{
System.out.println(“coding”);
}
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