Brian
2013-03-07 13:00:21 UTC
Q1 - Q13) Write the output for each of the first 13 conditionals.
Q14) Write a statement in your own words which summarize Q2) -- Q5).
Q15) Write a statement in your own word which summarize Q6) -- Q9).
A logical expression is a formula in which variables representing statements (a statement must be either true or false) or the boolean values themselves are combined in an unambiguous ways with && || ! (not).
Q16 - Q23) Write the result of each of the expressions 14 through 21.
Could you predict the output of these expressions?
Q24 - Q31) What would the output of each of the following expressions be?
true && (true || true)
true && (true || false)
true && (false || true)
true && (false || false)
false && (true || true)
false && (true || false)
false && (false || true)
false && (false || false)
Often logical expression can be simplified by using De Morgan's Laws. De Morgan's Laws state:
For all statements a and b (remember a statement must evaluate to be either true or false):
1) !(a && b) is equivalent to (!a) || (!b)
2) !(a || b) is equivalent to (!a) && (!b)
Note: these can be proved using the results of Q2 -- Q12 which are the basic definitions.
Q32) Express the negation of (x>2) &&(x<=3)
Q33) Let's consider the legal speed on an expressway. Often there is a minimum speed as well as a maximum legal speed. If the speed limit is 65 m.p.h. and the minimum speed is 45 m.p.h. we could state that if x represents a legal speed then it must be true that (x>=45) && (x<=65). Write an expression describing the illegal speed in the simplest way possible. Hint: Use De Morgan's Laws to simplify.
package day14;
public class Day14 {
public static void main(String[] args) {
System.out.println("1) 2 < 3 \t\t\t\t\tis "+(2<3));
System.out.println("2) true \t|| \ttrue \t\t\tis "+(true || true));
System.out.println("3) true \t|| \tfalse \t\t\tis "+(true || false));
System.out.println("4) false \t|| \ttrue \t\t\tis "+(false || true));
System.out.println("5) false \t|| \tfalse \t\t\tis "+(false || false));
System.out.println("6) true \t&& \ttrue \t\t\tis "+(true && true));
System.out.println("7) true \t&& \tfalse \t\t\tis "+(true && false));
System.out.println("8) false \t&& \ttrue \t\t\tis "+(false && true));
System.out.println("9) false \t&& \tfalse \t\t\tis "+(false && false));
System.out.println("10) !true \t\t\t\t\tis "+(!true));
System.out.println("11) !false \t\t\t\t\tis "+(!false));
System.out.println("12) !(!true) \t\t\t\t\tis "+(!(!true)));
System.out.println("13) !(!false) \t\t\t\t\tis "+(!(!false)));
System.out.println("14) true\t||\t(true && true) \tis "+(true||(true && true)));
System.out.println("15) true\t||\t(true && false) \tis "+(true||(true && false)));
System.out.println("16) true\t||\t(false && true) \tis "+(true||(false && true)));
System.out.println("17) true\t||\t(false && false) \tis "+(true||(false && false)));
System.out.println("18) false\t||\t(true && true) \tis "+(false||(true && true)));
System.out.println("19) false\t||\t(true && false) \tis "+(false||(true && false)));
System.out.println("20) false\t||\t(false && true) \tis "+(false||(false && true)));
System.out.println("21) false\t||\t(false && false) \tis "+(false||(false && false)));
}
}