Game Development Reference
In-Depth Information
6. Prime numbers
(a) Write a method Even which indicates whether a number passed as a parame-
ter is an even number. Determine what the best type is for the parameter and
the return value.
(b) Write a method MultipleOfThree that indicates whether its parameter is a mul-
tiple of three.
(c) Write a method MultipleOf with two parameters x and y , that determines if x
is a multiple of y .
(d) Write a method Divisible with two parameters x and y that determines if x is
divisible by y (so x/y should have no remainder).
(e) Write a method SmallestDivider that determines the smallest integer number
2 by which the parameter can be divided.
Hint: try the dividers one by one, and stop as soon as you found one.
(f) Write a method that determines if a number is a prime number. This means
that it is only divisible by 1 and by itself.
7. Drawing the memory
Given are the following class definitions:
class One
{
int x;
public One()
{
x=0;
}
public void SetX( int a)
{
x=a;
}
}
class Tw o
{
int x;
One o;
public Two(One b, int c)
{
o=b;
x=c+1;
}
public One GetO()
{
return o;
}
}
Search WWH ::




Custom Search