Thursday, September 29, 2011

Challenge 014’s Solution

In Challenge 14, the output displays “0.0”. This is because the expression “double n = 99/100” is written with int values for the numbers 99 and 100. Because of this, the result of 99 ÷ 100 must also be an int value, and therefore equals 0. The number 0 is converted to a double value after the function is performed, which is why the statement “0.0” is displayed. To combat this problem, one can do either of two solutions: first, one can simply write the numbers 99 and 100 as double values, replacing the previous expression with “double n = 99.0/100.0”. Because of their new notation, the resulting output will be “0.99”. Second, one can convert each number into a double value within the equation itself, replacing the previous expression with “double n = (double)99/(double)100”. This makes 99 and 100 into the quantities 99.0 and 100.0, respectively, resulting (again) in the output “0.99”.
 
−Phoenix

Monday, September 26, 2011

Challenge 011’s Solution

In Challenge 11, entering the code as−is creates an error message, saying that the method goFigure cannot be referenced from a static context. When the term “static” is removed from the “output” code−segment, then one cannot run the program. To combat this problem, one can add the word “static” in front  of the coding “double goFigure(int n)”.  When this is done, the output is “2.0 12”. At first, the challenge assigns n as an integer equal to 12. The method goFigure then has n perform the function “n % 7”, which means “the remainder of ‘n ÷ 7’ ”. This number is 5, and is then used in the next statement “12 / n”. Because n is assigned an “int” value, the answer is rounded to 2. After that, n is reassigned as a “double” value, making goFigure(n) equal 2.0. In the last bit of code, the value of goFigure(n), or 2.0, is printed on the screen, followed by a space and the original value of n, being 12; thus, when run, the output is “2.0 12”.
 
−Phoenix

Wednesday, September 21, 2011

Challenge 017’s Solution

Statements A, B, C, D, and E all have an output of true. Statement A requires both !A and !(B && !C) to be true. Because A, B, and C are all false, !A is “not false”, meaning it’s true.  Also, De Morgan’s Law states that “!(B && !C)” is the same as “!B || C”, and since !B is true, Statement A is true. Statement B requires either !A, !B, or !C to be true. While unnecessary, all three are true, so Statement B is true. Statement C states “!(A || B || C)”, which is the same as !A, !B, and !C. All of these mean “true”, so Statement C is true. Statement D states “!(A && B && C)”, which also means !A, !B, or !C. This statement is the same as Statement B, which is true, so Statement B is true. Finally, Statement E requires !A or !(B || !C) to be true. !A is true, so Statement E is true. That is why all five statements have an output of true.
 
−Phoenix

Tuesday, September 20, 2011

Challenge 016’s Solution

When the code is placed into BlueJ™, the following comes out in the Terminal window:
 
\* This is not
a comment *\
 
This is because of what the various symbols in the statement mean. When written between quotation marks in a String[] statement, the symbol “\\” outputs a “\” in the printed string, and “\n” causes the comment to continue on the next line, similar to what the “¶” symbol represents in modern English Writing. The rest of the phrase is printed because it too is between quotation marks.
 
−Phoenix

Monday, September 19, 2011

Challenge 015’s Solution

In Challenge 015, Statement I creates an error message. This is because it first makes “x” a double value of 14.7. Next, it tries to say that “int y = x”. This cannot be so, as an “int” value cannot equal a non−integer number. To correct this, one must make “x” an “int” value by placing “(int)” before 14.7, yielding the output “14”. Next, Statement II correctly yields the output “14”. While this statement has “x” as a double value of 14.7, the statement has the term “(int)” in front of “x”, making it an integer value before it claims that it is equal to “int y”. Therefore, no correction is necessary for Statement II. Finally, Statement III also creates an error message. This is because it tries to say that “int x” is equal to a non−integer number of 14.7. This should (again) be corrected by placing “(int)” before 14.7. This allows the statement to produce the number “14.0”, as the number 14 can be a double value. In conclusion, one could state that “int” values can be “double” values, but “double” values cannot be “int” values; similar to how integer numbers can be rational numbers, while rational numbers cannot be integer numbers.
 
−Phoenix

Friday, September 16, 2011

Challenge 008’s Solution

The answer to the solution is −1. The code places a starting value of “5”. It then says that as long as the statement “value ≥ 0” is true, it will subtract 2 from the value. When executed, “5 − 2 = 3”, and “3 ≥ 0”, so this repeats. “3 − 2 = 1” and “1 ≥ 0”, so the code repeats. “1 − 2 = −1”; however, the statement “−1 ≥ 0” isn’t true, so 2 is no longer subtracted from the value. The final bit of code says to show the value, which is why the solution of −1 shows up. The “while” statement says that as long as a condition is true, something will be performed.
 
−Phoenix

Wednesday, September 14, 2011

Challenge 009’s Solution

When x = true and y = false, all three expressions are “true”. Statement I is “true” if both condition 1 and condition 2 can be “true”. Condition 1 can be “true” with “x”, and condition 2 can be “not false” with “!y”. Statement II is also true if  both condition 1 and condition 2 can be “true”. Condition 1 can be “true” with “x”, while condition 2 requires both statements to be “true”; however, “!(x && y)” is the same as “(!x || !y)”, making condition 2 “not false” with “!y”. Finally, Statement III is “true” as long as one of the two conditions is “true”. Condition 1 requires both statements to be “true”, and “(x && !y)” is “true” and “not false”. That is why all three Statements in Challenge 009 are “true”.
 
−Phoenix

Tuesday, September 13, 2011

Challenge 013’s Solution

When in the Northeast corner of the Grid World, the Bug turns at 45° intervals until it faces a direction it can move forward in; or, in this case, South. The Bug then continues to move in that direction until colliding with another wall boundary, in which it then again continues turning at 45° intervals until it can move forward again in a West direction. Because of its starting position, the Bug will continuously travel in a square−shaped pattern.
 
−Phoenix

Friday, September 9, 2011

Challenge 010’s Solution

When the code for Challenge 10 is written in BlueJ™, an answer of 2.0 pops out. Initially, this makes no sense, as the equation appears to be d = √(4 + 5) ∕ 2, which should equal 2.1213… However, the variables for 4 and 5 have “int” before them in the code, forcing the equation to act like a Greatest Integer Function, which rounds the result to the greatest integer that is less than or equal to the nearest integer. Therefore, 2.1213 is rounded down to 2. When the phrase “int” is replaced with “double”, the result is 2.1213, supporting my hypothesis.
 
−Phoenix

Thursday, September 8, 2011

Challenge 012’s Solution

Statements I, II and III all print the number “1234”. I believe that this means that the “+” sign has two different meanings then in JAVA. When there aren’t any quotation marks in the problem, JAVA works like a regular calculator, with 12 × 100 + 34 = 1234. However, when there are quotation marks, the “+” sign merely combines the quoted expression with the added number, ignoring whether or not it makes mathematical sense that “12” + 34 = 1234. Therefore, the use of quotation marks is very important when programming mathematics in JAVA.
 
−Phoenix