Quiz 1 (Prelim) Flashcards
int num1 = 3, num2 = 2;
(num1 < num2)
(True or False)
F
double hours = 92.8;
(hours > 40.2)
(True or False)
T
char letter = ‘A’;
(‘A’ < letter)
(True or False)
F
int age = 1;
(age != 1)
(True or False)
F
double y = -2.3;
y >= 0.0;
(True or False)
F
x = false, y = false, z = false
!(x && y) || z
(True or False)
T
x = false, y = false, z = false
x || (z && (!y || x))
(True or False)
F
x = false, y = false, z = false
true || !z && y
(True or False)
T
x = false, y = false, z = false
z && x || y
(True or False)
F
x = false, y = false, z = false
false || !x && y
(True or False)
F
If either or both expressions evaluate to False, the _______ operator returns False.
AND
If either or both expressions evaluate to True, the _______ operator returns True.
OR
int x = 8;
if (x > 10)
…..System.out.println(“x is within the range. \n”);
System.out.println(“Section allows decision making. \n”);
Output:
Section allows decision making.
int x = 8;
if (x < 8)
{
…..System.out.println(“x is within the range. \n”);
…..System.out.println(“This is a true statement. \n”);
}
System.out.println(“And, after selection, the next statement is exeuted. \n”)
Output:
And, after selection, the next statement is exeuted.
int x = 8;
boolean found = true;
if (x == 6 || found)
…..System.out.println(“The equation is true. \n”);
System.out.println(“End of expression. \n”);
Output:
The equation is true.
int x = 8;
if (x >= 5)
{
}
else
…..System.out.println(“Have a good day. \n”);
System.out.println(“The value of x is” + x + “\n”);
Output:
The value of x is 8
int x = 8;
boolean found = true;
if (x != 6 && ! found)
…..System.out.println(“The expression is true. \n”);
else
…..System.out.println(“The expression is false. \n”);
System.out.println(“End of expression. \n”);
Output:
The expression is false.
End of expression.
int x = 8;
if (x > 0 && x > 10)
…..System.out.println(“x is in range. \n”);
else
…..System.out.println(“x is out of range. \n”);
Output:
x is out of range.
if (temp >= 70 && month >= 6)
…..System.out.println(“Wear sandals \n”);
else if (name == “Pat”)
…..System.out.println(“Wear white shoes\n”);
else
…..System.out.println(“Wear black shoes\n”);
int temp= 78; int month = 6; String name = “Pat”;
Output:
Wear sandals
if (temp >= 70 && month >= 6)
…..System.out.println(“Wear sandals \n”);
else if (name == “Pat”)
…..System.out.println(“Wear white shoes\n”);
else
…..System.out.println(“Wear black shoes\n”);
int temp= 70; int month = 5; String name = “Pat”;
Output:
Wear white shoes
if (temp >= 70 && month >= 6)
…..System.out.println(“Wear sandals \n”);
else if (name == “Pat”)
…..System.out.println(“Wear white shoes\n”);
else
…..System.out.println(“Wear black shoes\n”);
int temp= 60; int month = 5; String name = “Pat”;
Output:
Wear white shoes
if (temp >= 70 && month >= 6)
…..System.out.println(“Wear sandals \n”);
else if (name == “Pat”)
…..System.out.println(“Wear white shoes\n”);
else
…..System.out.println(“Wear black shoes\n”);
int temp= 60; int month = 6; String name = “Your name”;
Output:
Wear black shoes