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
2ab53980
Commit
2ab53980
authored
Jan 06, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zbieranie danych - list, set, treeset
parent
67861379
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
5 deletions
+90
-5
P2_Lista.java
src/main/java/p12_kolekcje/zbieranie_danych/P2_Lista.java
+6
-5
P3_HashSet.java
src/main/java/p12_kolekcje/zbieranie_danych/P3_HashSet.java
+40
-0
P4_TreeSet.java
src/main/java/p12_kolekcje/zbieranie_danych/P4_TreeSet.java
+44
-0
No files found.
src/main/java/p12_kolekcje/zbieranie_danych/P2_Lista.java
View file @
2ab53980
...
@@ -9,20 +9,21 @@ public class P2_Lista {
...
@@ -9,20 +9,21 @@ public class P2_Lista {
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
Scanner
scanner
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"Podaj rozmiar tablicy: "
);
List
<
String
>
lista
=
new
ArrayList
<>();
int
size
=
scanner
.
nextInt
();
scanner
.
nextLine
();
List
<
String
>
lista
=
new
ArrayList
<
String
>(
size
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
while
(
true
)
{
System
.
out
.
print
(
"Podaj imię: "
);
System
.
out
.
print
(
"Podaj imię: "
);
String
imie
=
scanner
.
nextLine
();
String
imie
=
scanner
.
nextLine
();
if
(
imie
.
isEmpty
())
break
;
lista
.
add
(
imie
);
lista
.
add
(
imie
);
}
}
System
.
out
.
println
(
"Liczba elementów: "
+
lista
.
size
());
System
.
out
.
println
(
"Cała lista: "
+
lista
);
System
.
out
.
println
(
"Cała lista: "
+
lista
);
System
.
out
.
println
();
System
.
out
.
println
();
// Podstawowa operacja odczytu z listy (poza pętlą for-each) to odczyt z określonej pozycji, podobnie jak dla tablic.
// Dla list używa się metody get(i)
System
.
out
.
println
(
"Podawaj liczby - numery pozycji. Aby zakończyć, wpisz -1"
);
System
.
out
.
println
(
"Podawaj liczby - numery pozycji. Aby zakończyć, wpisz -1"
);
while
(
true
)
{
while
(
true
)
{
System
.
out
.
print
(
"nr: "
);
System
.
out
.
print
(
"nr: "
);
...
...
src/main/java/p12_kolekcje/zbieranie_danych/P3_HashSet.java
0 → 100644
View file @
2ab53980
package
p12_kolekcje
.
zbieranie_danych
;
import
java.util.HashSet
;
import
java.util.Scanner
;
import
java.util.Set
;
public
class
P3_HashSet
{
public
static
void
main
(
String
[]
args
)
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
Set
<
String
>
zbior
=
new
HashSet
<>();
while
(
true
)
{
System
.
out
.
print
(
"Podaj imię: "
);
String
imie
=
scanner
.
nextLine
();
if
(
imie
.
isEmpty
())
break
;
zbior
.
add
(
imie
);
}
System
.
out
.
println
(
"Liczba elementów: "
+
zbior
.
size
());
System
.
out
.
println
(
"Cały zbiór: "
+
zbior
);
System
.
out
.
println
();
// Podstawowa operacja odczytu dla zbioru (poza pętlą for-each) to sprawdzenie, czy wartość należy do zbioru.
System
.
out
.
println
(
"Podawaj imiona, aby sprawdzić, czy należą do zbioru. Aby zakończyć, podaj pusty napis."
);
while
(
true
)
{
System
.
out
.
print
(
"imię: "
);
String
imie
=
scanner
.
nextLine
();
if
(
imie
.
isEmpty
())
break
;
if
(
zbior
.
contains
(
imie
))
{
System
.
out
.
println
(
"Imię "
+
imie
+
" należy do zbioru."
);
}
else
{
System
.
out
.
println
(
"Imię "
+
imie
+
" NIE należy do zbioru."
);
}
}
System
.
out
.
println
(
"KONIEC"
);
}
}
src/main/java/p12_kolekcje/zbieranie_danych/P4_TreeSet.java
0 → 100644
View file @
2ab53980
package
p12_kolekcje
.
zbieranie_danych
;
import
java.text.Collator
;
import
java.util.Locale
;
import
java.util.Scanner
;
import
java.util.Set
;
import
java.util.TreeSet
;
public
class
P4_TreeSet
{
public
static
void
main
(
String
[]
args
)
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
// Set<String> zbior = new TreeSet<>();
Set
<
String
>
zbior
=
new
TreeSet
<>(
Collator
.
getInstance
());
// Set<String> zbior = new TreeSet<>(Collator.getInstance(Locale.of("pl", "PL")));
while
(
true
)
{
System
.
out
.
print
(
"Podaj imię: "
);
String
imie
=
scanner
.
nextLine
();
if
(
imie
.
isEmpty
())
break
;
zbior
.
add
(
imie
);
}
System
.
out
.
println
(
"Liczba elementów: "
+
zbior
.
size
());
System
.
out
.
println
(
"Cały zbiór: "
+
zbior
);
System
.
out
.
println
();
// Podstawowa operacja odczytu dla zbioru (poza pętlą for-each) to sprawdzenie, czy wartość należy do zbioru.
System
.
out
.
println
(
"Podawaj imiona, aby sprawdzić, czy należą do zbioru. Aby zakończyć, podaj pusty napis."
);
while
(
true
)
{
System
.
out
.
print
(
"imię: "
);
String
imie
=
scanner
.
nextLine
();
if
(
imie
.
isEmpty
())
break
;
if
(
zbior
.
contains
(
imie
))
{
System
.
out
.
println
(
"Imię "
+
imie
+
" należy do zbioru."
);
}
else
{
System
.
out
.
println
(
"Imię "
+
imie
+
" NIE należy do zbioru."
);
}
}
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