wrong:
System.out.println(array);right
System.out.println(Arrays.toString(array));
System.out.println(array);right
System.out.println(Arrays.toString(array));
public static <T> String join(T[] array, String delimiter)
{
if (array.length == 0)
return "";
StringBuilder builder = new StringBuilder();
builder.append(array[0]);
for (int i = 1; i < array.length; i++)
builder.append(delimiter).append(array[i]);
return builder.toString();
}
divide a b = a / b
two_thirds = divide 2 3
div = divide
two_thirds = div 2 3
invert a = divide 1 a
one_half = invert 2
invert = divide 1
one_half = invert 2
def divide(a):
return lambda b: a / b
two_thirds = divide(2)(3)
divide(2)
is a function that takes 1 argument called b
. When it gets b
it divides 2/b
and returns that. All functions in Haskell behave this way.
negate a = -a
divide a b = a / b
-- here's a list of numbers:
numbers = [1,2,5,10]
-- the map function takes a function and
-- applies it to each item of a list
negated_numbers = map negate numbers
-- produces: [-1,-2,-5,-10]
-- here's our invert function
invert = divide 1
inverted_numbers = map invert numbers
-- produces: [1, 0.5, 0.2, 0.1]
-- equivalently:
inverted_numbers = map (divide 1) numbers
-- more complex:
-- this function inverts a list of numbers
invert_list = map invert
inverted_numbers = invert_list numbers
(a)-b
. Are we subtracting (a)
from b
, or are we casting -b
to type a
? I have news: the Java compiler struggles with this same problem.
Integer i1 = (int)3; // valid
Integer i2 = (int)-3; // valid
Integer i3 = (int)-(3); // valid
Integer i4 = (Integer)3; // valid
Integer i5 = (Integer)-3; // compile error
Integer i6 = (Integer)-(3); // compile error
Integer i7 = (Integer)(-3); // valid
(Type)expression
casting syntax is troublesome.
Public Sub PrintThings()
Console.WriteLine("3" + "6")
Console.WriteLine(3 & 6)
End Sub
public void printThings() {
System.out.println("3" + "6");
System.out.println(3 & 6);
}
let a, b, c be Non-Negative Integers
let f(x, y) be a function such that:
f(a, b) = c
f(b, a) = c
f(a, c) = b
f
?a
and b
. Use what you think f
is and the formula f(a, b) = c
to calculate c
. Then see if the other two formulas are true with those values of a
, b
, and c
.