println(); println("A string"); println("two", "strings");
abs(10) // returns an int
abs(-1.5) // returns a float
fill(255); fill(0, 0, 255); fill(0, 255, 0, 255);
B - a perfect match for the parameters
invalid - first argument must fit in an int (both methods would require casting for a long first argument)
B - the least amount of widening - only first argument needs to be widened to an int
invalid - second argument must fit in an int or a long (both methods would require casting for a float second argument)
A - a perfect match for the parmeters (also couldn't work for B)
B - less widening required (2 char to 2 int - method A would require one of the casts to a long which requires more widening)
void rollDie (int rolls)
{
if (rolls < 1)
println("Invalid argument - rolls must be at least 1");
for (int i = 1; i <= rolls; i++)
println((int)random(1, 7));
}
void rollDie (int rolls, int faces)
{
if (rolls < 1)
println("Invalid argument - rolls must be at least 1");
if (faces < 4)
println("Invalid argument - faces must be at leat 4");
elsefor (int i = 1; i <= rolls; i++)
println((int)random(1, faces+1));
}
int average(long a, long b)
{
return (int)((a + b) / 2);
}
float average(float a, float b)
{
return (a + b) / 2;
}
void setup()
{
int m = average(8, 7L);
float x = average(2.0, 3);
println(m);
println(x);
}