Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kurs_java_alx_20240321
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
kurs_java_alx_20240321
Commits
1e86bd0a
Commit
1e86bd0a
authored
Apr 09, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
teoria funkcji
parent
6c61aaa4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
0 deletions
+83
-0
A_PierwszeFunkcje.java
src/p09_funkcje/A_PierwszeFunkcje.java
+33
-0
B_ParametryIWynik.java
src/p09_funkcje/B_ParametryIWynik.java
+50
-0
No files found.
src/p09_funkcje/A_PierwszeFunkcje.java
0 → 100644
View file @
1e86bd0a
package
p09_funkcje
;
public
class
A_PierwszeFunkcje
{
// Wewnątrz klasy można definiować wiele "metod" / "funkcji".
static
void
aaa
()
{
System
.
out
.
println
(
"aaa, kotki dwa"
);
System
.
out
.
println
(
" szare bure obydwa"
);
}
static
void
xxx
()
{
System
.
out
.
println
(
"XXX , ale to się nie wypisze, bo nikt nie wywołał"
);
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Początek programu"
);
aaa
();
aaa
();
System
.
out
.
println
(
"Teraz wywołam bbb(3)"
);
bbb
(
3
);
System
.
out
.
println
(
"Koniec programu"
);
}
static
void
bbb
(
int
ileRazy
)
{
System
.
out
.
println
(
"\nPoczątek bbb"
);
for
(
int
i
=
0
;
i
<
ileRazy
;
i
++)
{
aaa
();
}
System
.
out
.
println
(
"Koniec bbb\n"
);
}
}
src/p09_funkcje/B_ParametryIWynik.java
0 → 100644
View file @
1e86bd0a
package
p09_funkcje
;
public
class
B_ParametryIWynik
{
// Funkcja może zwracać wynik:
// - przed nazwą funkcji musi być podany typ wyniku
// - w treści musi być return (może być więcej niż jeden), poprzez który funkcja ustala wartość wyniku
static
String
hello
()
{
return
"Hello world"
;
}
// Funkcja może mieć zadeklarowane parametry, czyli takie zmienne,
// których wartość przekazuje się podczas wywołania
static
void
powitaj
(
String
imie
,
String
miasto
)
{
System
.
out
.
println
(
"Witaj "
+
imie
+
" z miasta "
+
miasto
);
}
static
long
kwadrat
(
int
x
)
{
return
(
long
)
x
*
x
;
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"1:"
);
hello
();
// zauważmy, że napis Hello world nie pojawił się jeszce na ekranie.
// Samo wywołanie funkcji, która robi return, nie pokazuje nigdzie zwróconej wartości.
System
.
out
.
println
(
"2:"
);
String
s
=
hello
();
System
.
out
.
println
(
"3:"
);
System
.
out
.
println
(
"Wynikiem wywołanie jest "
+
s
);
System
.
out
.
println
(
"4:"
);
// można wywołanie funkcji wstawić do printa:
System
.
out
.
println
(
hello
());
System
.
out
.
println
(
"5: "
+
hello
().
toUpperCase
());
System
.
out
.
println
();
powitaj
(
"Ala"
,
"Łódź"
);
powitaj
(
"Patryk"
,
"Żyrardów"
);
powitaj
(
"Patryk"
,
"Prudnik"
);
System
.
out
.
println
();
long
wynik
=
kwadrat
(
2
);
System
.
out
.
println
(
wynik
);
// można też od razu printować:
System
.
out
.
println
(
kwadrat
(
30
));
System
.
out
.
println
(
kwadrat
(
1000000
));
}
}
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