Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_20251009
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
alx_20251009
Commits
e45d97e4
Commit
e45d97e4
authored
Oct 10, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Interfejsy i lambdy
parent
67fc56e9
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
106 additions
and
0 deletions
+106
-0
FunkcjaLiczbowa.java
src/main/java/p06_lambdy/FunkcjaLiczbowa.java
+7
-0
KolekcjaFunkcji.java
src/main/java/p06_lambdy/KolekcjaFunkcji.java
+37
-0
MojFrameworkFunkcyjny.java
src/main/java/p06_lambdy/MojFrameworkFunkcyjny.java
+11
-0
MojProgramFuncyjny.java
src/main/java/p06_lambdy/MojProgramFuncyjny.java
+20
-0
Przyklady.java
src/main/java/p06_lambdy/Przyklady.java
+31
-0
No files found.
src/main/java/p06_lambdy/FunkcjaLiczbowa.java
0 → 100644
View file @
e45d97e4
package
p06_lambdy
;
public
interface
FunkcjaLiczbowa
{
double
oblicz
(
double
arg
);
}
src/main/java/p06_lambdy/KolekcjaFunkcji.java
0 → 100644
View file @
e45d97e4
package
p06_lambdy
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
public
class
KolekcjaFunkcji
{
static
void
main
()
{
Map
<
String
,
FunkcjaLiczbowa
>
funkcje
=
new
LinkedHashMap
<>();
funkcje
.
put
(
"inc"
,
x
->
x
+
1
);
funkcje
.
put
(
"dec"
,
x
->
x
-
1
);
funkcje
.
put
(
"sqr"
,
x
->
x
*
x
);
funkcje
.
put
(
"sqrt"
,
Math:
:
sqrt
);
funkcje
.
put
(
"razy2"
,
x
->
2
*
x
);
funkcje
.
put
(
"razy10"
,
x
->
10
*
x
);
while
(
true
)
{
String
f
=
IO
.
readln
(
"Podaj funkcje: "
);
if
(
f
.
isEmpty
())
break
;
double
arg
=
Double
.
parseDouble
(
IO
.
readln
(
"Podaj liczbę: "
));
FunkcjaLiczbowa
funkcjaLiczbowa
=
funkcje
.
get
(
f
);
if
(
funkcjaLiczbowa
==
null
)
{
System
.
out
.
println
(
"Nieznana funkcja"
);
continue
;
}
double
wynik
=
funkcjaLiczbowa
.
oblicz
(
arg
);
System
.
out
.
printf
(
"%s(%s) = %s\n"
,
f
,
arg
,
wynik
);
}
System
.
out
.
println
();
funkcje
.
forEach
((
nazwa
,
funkcja
)
->
{
double
arg
=
100
;
System
.
out
.
printf
(
"%s(%s) = %s\n"
,
nazwa
,
arg
,
funkcja
.
oblicz
(
arg
));
});
}
}
src/main/java/p06_lambdy/MojFrameworkFunkcyjny.java
0 → 100644
View file @
e45d97e4
package
p06_lambdy
;
public
class
MojFrameworkFunkcyjny
{
public
static
void
zastosujDoTablicy
(
double
[]
t
,
FunkcjaLiczbowa
f
)
{
for
(
int
i
=
0
;
i
<
t
.
length
;
i
++)
{
t
[
i
]
=
f
.
oblicz
(
t
[
i
]);
}
}
}
src/main/java/p06_lambdy/MojProgramFuncyjny.java
0 → 100644
View file @
e45d97e4
package
p06_lambdy
;
import
java.util.Arrays
;
import
static
p06_lambdy
.
MojFrameworkFunkcyjny
.
zastosujDoTablicy
;
public
class
MojProgramFuncyjny
{
static
void
main
()
{
double
[]
a
=
{
1
,
2
,
4
,
16
,
9
,
81
};
System
.
out
.
println
(
Arrays
.
toString
(
a
));
zastosujDoTablicy
(
a
,
x
->
x
+
1
);
System
.
out
.
println
(
Arrays
.
toString
(
a
));
zastosujDoTablicy
(
a
,
x
->
x
-
1
);
System
.
out
.
println
(
Arrays
.
toString
(
a
));
zastosujDoTablicy
(
a
,
Math:
:
sqrt
);
System
.
out
.
println
(
Arrays
.
toString
(
a
));
zastosujDoTablicy
(
a
,
x
->
x
*
x
);
System
.
out
.
println
(
Arrays
.
toString
(
a
));
}
}
src/main/java/p06_lambdy/Przyklady.java
0 → 100644
View file @
e45d97e4
package
p06_lambdy
;
public
class
Przyklady
{
static
void
main
()
{
FunkcjaLiczbowa
f2
=
x
->
2
*
x
;
System
.
out
.
println
(
f2
.
oblicz
(
10
));
FunkcjaLiczbowa
f3
=
(
double
x
)
->
{
while
(
x
<
100
)
{
x
+=
10
;
}
return
x
;
};
System
.
out
.
println
(
f3
.
oblicz
(
67.5
));
// method reference
FunkcjaLiczbowa
pierwiastek
=
Math:
:
sqrt
;
FunkcjaLiczbowa
pierwiastek2
=
x
->
Math
.
sqrt
(
x
);
System
.
out
.
println
(
pierwiastek
.
oblicz
(
16
));
System
.
out
.
println
(
pierwiastek2
.
oblicz
(
2
));
System
.
out
.
println
();
System
.
out
.
println
(
f2
.
getClass
());
System
.
out
.
println
(
f3
.
getClass
().
getSimpleName
());
if
(
f2
instanceof
FunkcjaLiczbowa
)
{
System
.
out
.
println
(
"tak tak"
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment