Thursday, February 23, 2012

Boolean Operators

The easiest way to think of boolean operators is to think of them like a sentence.
| the OR operator 
 Think of it as an OR in a sentence. Is this sentence true: My name is Joshua OR I have never seen a computer.
The sentence is still true because I said OR and had a true statement.
A         B             A|B
false     false         false
true      false         true
false     true          true
true      true          true
As seen in the table above, the only way to make an or statement false is that if both statements are false.

& the AND operator 
 Just like OR but using the word AND. Is this sentence true: My name is Joshua AND I have never seen a computer. This sentence is obviously false because the second statement is false.

A         B              A&B
false     false         false
true      false         false
false     true          false
true      true          true
^ the XOR operator 
XOR or EXCLUSIVE OR means if ONE and ONLY ONE is true, the sentence is true. Since XOR doesn't equate to any english metaphor, I'll just post the table.
A         B             A^B
false     false         false
true      false         true
false     true          true
true      true          false
! the NOT operator 
The easiest to learn. NOT just switches the boolean. !true = false. !false=true.
== the EQUAL TO operator 
Similarly easy,  EQUAL TO just checks if either side is equal.
This works with number, strings, objects, anything.
!= the NOT EQUAL TO operator 
Just like equals, but NOT. Checks if the two ARENT equal.
The complete table:
A         B             A|B       A&B      A^B      !A
false     false         false     false    false    true
true      false         true      false    true     false
false     true          true      false    true     true
true      true          true      true     false    false
This and others like it have been brought to you by the Josh Cannon foundation. 

Thursday, February 16, 2012

A list of ALL the Java Keywords & rules for variable names

Java Keywords:
abstract, boolean, break, case, catch, class, continue, char, const, default, do, double, else, extends, final, finally, for, if, implements, import, instanceof, int, interface, new, null, package, private, protected, public, return, static, super, this, throw, throws, try, void, while.

Rules for variable names:
Other than not using a keyword as a variable name, a name has to start with a letter, an underscore, or a $. A name cannot have any spaces or special characters.
 
Examples:
 Which of the following are valid identifiers in Java?
I. 2far
II. twoFar
III. TWO_FAR
A. I only    B. II only    C. III only    D. I and II    E. II and III
The answer is E because I has a number in the front.

Which of the following are Java keywords?
I. method
II. throws
III. foreach
A. I only    B. II only    C. III only    D. II and III    E. none of these
The answer is B since "throws" is the only java keyword out of the three.

-This post a direct result from the mind of Joshua Cannon

Thursday, February 9, 2012

multiplying two non-decimal numbers.

Although there might be some amazing trick to this, the easiest to do is to convert the numbers to base 10, do the operation, then convert the solution back if necissary.
Ex. 10100101₂ times 101₂?
10100101₂ is 165
101₂ is 5
165 * 5 is 825.

Convert it to whatever base the answer is in and voila, you have completed the first problem.

-Josh