|
(I took AP COmputer Science A last year and recieved a 5, Iw as going to take AB this year, but too few students signed up for it so it was concelled. I know the stuff though.)
For the first problem:
You will want to begin by analyzing indonesia().
Let's say p = 0, then p/q would also be zero, so indonesia would return q.
If q was zero, it would through a DivideByZeroException.
If p was not equal to zero, then it would go through again with p = q and q = p/q.
Let's take two arbitrary numbers, p = 4 and q = 2. p/q = 2, so it calls indonesia(2, 2), 2/2 (p/q) = 1, so it calls indonesia(2, 1). p/q (2/1) is still 2, so it calls indonesia(1, 2). Now, 1/2 is 0.5, BUT since indonesia returns an int, it is truncated to zero, therefore indonesia(4, 2) returns 2.
Now we should try with p<q, so let's say p=2 and q=4:
step 1: p/q = 2/4 = 0.5, truncated to 0, returns 4.
so there is only one step. We see that the method behaves differently for the two situations.
So this is what we have found (looking at teh possible answers):
- If p>q, the method returns some number (I don't think we need to delve further than that)
- If p<=q... if p<q the method returns q, if p = q, the method returns p.
- If both p and q are >0, it returns some number.
Now for the second method thailand().
...
So, yeah, the only way is to go throgh it logically and possibly plugging in numbers.
~~~~~~~~~~~~~~~~~~~~~~~~
For the first one, if a is true, it is always true since a is true and a or b is true (since a is true) it is false in any other case. For the second statement, if a is false teh whole thing is always gfalse since a is false and a && b is false (since a is false it doesn't amytter what b is). if a is true: true || something else, it is always true.
Statement 1: if a = true then true, if a = false then false
Statement 2: if a = true then true, if a = false then false
Therefore you can eliminate E (since they are equivalent for the above cases), D (since it doesn't matter what b is), C (they are equivalent when a is false), B, (they are equivalent for the cases above). SO I guesswe found teh answer.
On the test, some questions will take longer time, some will take one or two seconds, as long as you know exactly what to do and you start doing it immediately you should be fine. And remember to write all over your test, it really helps, especially when working out recursion (you will need to trace the stack which can get really confusing).
Hope that helped.
__________________
If you need help with Java, you can go to javaforum.tk and get answers quickly.
Programmer YouLikeJava = new JavaProgrammer("Eyvind");
YouLikeJava.printInfo();
YouLikeJava.setWeb("You Like Java?");
|