help with java assignment  
Author Message
dietrich.heese.boutin





PostPosted: 2007-1-19 0:57:00 Top

java-programmer, help with java assignment Was just hoping someone could shed a bit of light on how to approach
this assignment. It would seem we have to determine the value of a in
order to determine how many times the method m() is called, but there
doesn't seem to be enough information to determine a's value. Any tips
would be greatly appreciated...

Many Thanks


For each of the following snippets of code, give the number of times
method m() is called, with a brief explanation. Assume that a and b are
nonnegative integers.
Snippet A

for (int i = a; i < a*a; ++i) {
m();
}
int i = 0; int j = a;
while (i <= j) {
++i;
m();
--j;
}

Snippet B

For this one, first we define a method m1:

public static void m1(int a) {
for (int i = 0; i <= a*a; ++i) {
m();
}
}

Now the snippet:

m1(a*a);

Snippet C

for (int i = a; i != a + b; i += 2) {
for (int j = a/2; j > 0; --j) {
for (int k = 1; k < a; ++k) {
m();
}
}
}

Snippet D

for (int i = 0; i < a; ++i) {
for (int j = 148; j < i; ++j) {
m();
}
}

 
Gordon Beaton





PostPosted: 2007-1-19 1:07:00 Top

java-programmer >> help with java assignment On 18 Jan 2007 08:57:01 -0800, email***@***.com wrote:
> Was just hoping someone could shed a bit of light on how to approach
> this assignment. It would seem we have to determine the value of a in
> order to determine how many times the method m() is called, but there
> doesn't seem to be enough information to determine a's value. Any tips
> would be greatly appreciated...

I don't think you're expected to determine a specific number for each
of the examples. I think you should express the answers in terms of a.
For example, m() might be called "2a" times, "a squared" times, etc.

/gordon

--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
dietrich.hb





PostPosted: 2007-1-19 2:32:00 Top

java-programmer >> help with java assignment Thanks, that was what I was thinking.