Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20231104-KursPodstawowyALX
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
20231104-KursPodstawowyALX
Commits
eb4ab4d1
Commit
eb4ab4d1
authored
Jan 06, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
słowniki
parent
2ab53980
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
0 deletions
+90
-0
P5_HashMap.java
src/main/java/p12_kolekcje/zbieranie_danych/P5_HashMap.java
+45
-0
P6_TreeMap.java
src/main/java/p12_kolekcje/zbieranie_danych/P6_TreeMap.java
+45
-0
No files found.
src/main/java/p12_kolekcje/zbieranie_danych/P5_HashMap.java
0 → 100644
View file @
eb4ab4d1
package
p12_kolekcje
.
zbieranie_danych
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Scanner
;
public
class
P5_HashMap
{
public
static
void
main
(
String
[]
args
)
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
// w tym przykładzie dla imienia osoby pamiętamy wiek tej osoby
Map
<
String
,
Integer
>
slownik
=
new
HashMap
<>();
while
(
true
)
{
System
.
out
.
print
(
"Podaj imię: "
);
String
imie
=
scanner
.
nextLine
();
if
(
imie
.
isEmpty
())
break
;
System
.
out
.
print
(
"Podaj wiek: "
);
int
wiek
=
scanner
.
nextInt
();
scanner
.
nextLine
();
slownik
.
put
(
imie
,
wiek
);
}
System
.
out
.
println
(
"Liczba elementów: "
+
slownik
.
size
());
System
.
out
.
println
(
"Cały słownik: "
+
slownik
);
System
.
out
.
println
();
// Podstawowa operacja odczytu dla słownika to odczyt wartości z miejsca wskazanego kluczem.
System
.
out
.
println
(
"Podawaj imiona. Aby zakończyć, podaj pusty napis."
);
while
(
true
)
{
System
.
out
.
print
(
"imię: "
);
String
imie
=
scanner
.
nextLine
();
if
(
imie
.
isEmpty
())
break
;
Integer
wiek
=
slownik
.
get
(
imie
);
if
(
wiek
==
null
)
{
System
.
out
.
println
(
"Nie znam takiej osoby"
);
}
else
{
System
.
out
.
println
(
"Osoba "
+
imie
+
" ma "
+
wiek
+
" lat."
);
}
}
System
.
out
.
println
(
"KONIEC"
);
}
}
src/main/java/p12_kolekcje/zbieranie_danych/P6_TreeMap.java
0 → 100644
View file @
eb4ab4d1
package
p12_kolekcje
.
zbieranie_danych
;
import
java.util.Map
;
import
java.util.Scanner
;
import
java.util.TreeMap
;
public
class
P6_TreeMap
{
public
static
void
main
(
String
[]
args
)
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
// w tym przykładzie dla imienia osoby pamiętamy wiek tej osoby
Map
<
String
,
Integer
>
slownik
=
new
TreeMap
<>();
while
(
true
)
{
System
.
out
.
print
(
"Podaj imię: "
);
String
imie
=
scanner
.
nextLine
();
if
(
imie
.
isEmpty
())
break
;
System
.
out
.
print
(
"Podaj wiek: "
);
int
wiek
=
scanner
.
nextInt
();
scanner
.
nextLine
();
slownik
.
put
(
imie
,
wiek
);
}
System
.
out
.
println
(
"Liczba elementów: "
+
slownik
.
size
());
System
.
out
.
println
(
"Cały słownik: "
+
slownik
);
System
.
out
.
println
();
// Podstawowa operacja odczytu dla słownika to odczyt wartości z miejsca wskazanego kluczem.
System
.
out
.
println
(
"Podawaj imiona. Aby zakończyć, podaj pusty napis."
);
while
(
true
)
{
System
.
out
.
print
(
"imię: "
);
String
imie
=
scanner
.
nextLine
();
if
(
imie
.
isEmpty
())
break
;
Integer
wiek
=
slownik
.
get
(
imie
);
if
(
wiek
==
null
)
{
System
.
out
.
println
(
"Nie znam takiej osoby"
);
}
else
{
System
.
out
.
println
(
"Osoba "
+
imie
+
" ma "
+
wiek
+
" lat."
);
}
}
System
.
out
.
println
(
"KONIEC"
);
}
}
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