Question:
Java programming Help Conditionals?
Brian
2013-03-07 13:00:21 UTC
Can someone help me answer these java questions with the given code?

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)));
}


}
Four answers:
TheMadProfessor
2013-03-07 13:39:18 UTC
1-13 and 16-23 are pretty basic, once you pick out the condition from all the tabs and such. For example, #1 is " 2 < 3", which obviously is true.



14 and 15. These are the basic truth tables for OR and AND, respectively.



24-31 are only slightly more complex...just remember that parenthesis modifies the order of evaluation with items inside them are evaluated before those outside them. For example, on #25:

true AND (true OR false) -> true AND true -> true



32. By DeMorgan 1, !((x>2)&&(x<=3)) -> !(x>2) || !(x<=3)

If x is not > 2, it must be <= 2. Similarly, if x is not <= 3, it must be > 3

Therefore, !(x>2) || !(x<=3) -> (x <= 2) || (x > 3)

That is indeed the negation of the original.



33. This could be done similarly to 32.
2016-10-29 00:44:19 UTC
There are a honest quantity of different techniques this software may be completed. you're able to do it using a for loop and if-else-if, or using a swap fact, in spite of the incontrovertible fact that a at the same time as loop and turn fact are the reuirements for this methodology. In eithercase, i will anticipate that using unicode is a robust concept. we at the instant are not here to do your homework for you, yet we are here to help. to three quantity this additionally supplies us prepare too. conserving a char datatype would be a usual step and to then set it to sixty 5: char letter = sixty 5; in case you attempt to print this out, you will get the end result "A". Unicode is going on for all letters of the alphabet, so it truly is in many cases used to print out all letters of the alphabet. All it is left is to set it in a at the same time as loop, use a swap fact to discover the vowels, and to increment on the tip of the at the same time as loop to break the loop as quickly as all letters have been revealed. a rapid lesson on swap statements: swap statements take in an enter and then swap between situations to envision if the two tournament. it is incredibly like a logically equivalence in discrete math and programming. If the two are equivalent, the situation is met. So, swap (enter) { case one million: break; case 2: break; case 3: break; default: break; } If the enter the place 2, then case 2 would be activated. If not one of the case values tournament the enter, then it is going to bypass to default. characters additionally artwork, yet you may could declare the situations first break breaking: case 'C': case 'c': gadget.out.println("however'); break; the end result may be if c or C have been entered, then "however" would be revealed. you're able to think of of the thank you to apply this with unicode fee. in spite of the incontrovertible fact that, it is purely a real way of doing it. stable success, ~Barolb
2013-03-10 16:54:43 UTC
of cause false.
2013-03-10 20:44:32 UTC
true.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...