Commit 4232948e by Patryk Czarnik

MojFrameworkFunkcyjny

parent e535b005
package p25_lambdy;
public class MojFrameworkFunkcyjny {
// stosuje podaną funkcję do wszystkich elementów tablicy
public static void zastosujFunkcjeDoTablicy(double[] t, FunkcjaLiczbowa f) {
for (int i = 0; i < t.length; i++) {
t[i] = f.oblicz(t[i]);
}
}
}
package p25_lambdy;
import java.util.Arrays;
public class UzycieFrameworku {
public static void main(String[] args) {
double[] a = {0, 1, 2, -5, 15, 35};
System.out.println(Arrays.toString(a));
MojFrameworkFunkcyjny.zastosujFunkcjeDoTablicy(a, x -> x+1);
System.out.println(Arrays.toString(a));
MojFrameworkFunkcyjny.zastosujFunkcjeDoTablicy(a, x -> x*x);
System.out.println(Arrays.toString(a));
MojFrameworkFunkcyjny.zastosujFunkcjeDoTablicy(a, arg -> Math.sqrt(arg));
System.out.println(Arrays.toString(a));
MojFrameworkFunkcyjny.zastosujFunkcjeDoTablicy(a, Math::sqrt);
System.out.println(Arrays.toString(a));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment