Usually there's a problem that uses numbers and bitwise operators. The way to do these problems is to convert both numbers into binary and line them up like you would with addition or subtraction. Then you pretend as if the 1s were trues, and 0s were false, then evaluate using the operator downward.
Ex: 5&12 101
1100
0100 - since the 4s place is the only one that has 1&1 or True&True
Then you convert the number back into decimal. So the answer would be 4.
Ex: 8|10 1000
1010
1010 - sine t|t = t and 0|t=t
The answer is 10.
-Josh
Friday, March 9, 2012
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.
& 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.
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.
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.
Just like equals, but NOT. Checks if the two ARENT equal.
The complete table:
| 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|Bfalse 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
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
Thursday, January 5, 2012
Collections
Stacks:
Items stored in Last In First Out order, or in other words, the items are returned in the opposite order in which they were entered. Imagine a stack of plates at an all-you-can-eat buffet. The last plates put on the stack are the first ones that are taken by the customer.
Example:
Stack<Integer> buffet = new Stack<Integer>();
buffet.push(1); // stack is now [1]
buffet.push(2); // stack is now [1, 2]
buffet.push(3); // stack is now [1, 2, 3]
buffet.pop(); // returns the last item entered and removes it from the stack //3
buffet.peek(); // returns the last item entered but does not remove it from the stack //2
Queues:
Items stored in First In First Out, or in other words, items are returned in the order they are put in. Imagine a line, the first person in line is the first person that leaves the line.
Example:
Queue<Integer> line = new PriorityQueue<Integer>();
line.add(1); // queue is now [1]
line.add(2); // queue is now [1, 2]
line.add(3); // queue is now [1, 2, 3]
line.remove(); // returns the first item entered and removes it from the queue // 1
line.peek(); // returnsthe first item entered but does not remove it from the queue // 2
Items stored in Last In First Out order, or in other words, the items are returned in the opposite order in which they were entered. Imagine a stack of plates at an all-you-can-eat buffet. The last plates put on the stack are the first ones that are taken by the customer.
Example:
Stack<Integer> buffet = new Stack<Integer>();
buffet.push(1); // stack is now [1]
buffet.push(2); // stack is now [1, 2]
buffet.push(3); // stack is now [1, 2, 3]
buffet.pop(); // returns the last item entered and removes it from the stack //3
buffet.peek(); // returns the last item entered but does not remove it from the stack //2
Queues:
Items stored in First In First Out, or in other words, items are returned in the order they are put in. Imagine a line, the first person in line is the first person that leaves the line.
Example:
Queue<Integer> line = new PriorityQueue<Integer>();
line.add(1); // queue is now [1]
line.add(2); // queue is now [1, 2]
line.add(3); // queue is now [1, 2, 3]
line.remove(); // returns the first item entered and removes it from the queue // 1
line.peek(); // returnsthe first item entered but does not remove it from the queue // 2
Subscribe to:
Posts (Atom)