Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SzkolenieALX_ProjektPatryka
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
SzkolenieALX_ProjektPatryka
Commits
5265c34d
Commit
5265c34d
authored
Jun 13, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ZbieranieDanych2_Lista
parent
26867bd8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
ZbieranieDanych2_Lista.java
...p12_kolekcje/zbieranie_danych/ZbieranieDanych2_Lista.java
+39
-0
No files found.
src/p12_kolekcje/zbieranie_danych/ZbieranieDanych2_Lista.java
0 → 100644
View file @
5265c34d
package
p12_kolekcje
.
zbieranie_danych
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Scanner
;
public
class
ZbieranieDanych2_Lista
{
public
static
void
main
(
String
[]
args
)
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
System
.
out
.
println
(
"Podawaj kolejne imiona, a zakończ pustym napisem (naciśnij enter)"
);
List
<
String
>
lista
=
new
ArrayList
<>();
for
(;;)
{
System
.
out
.
print
(
"Podaj kolejne imię: "
);
String
imie
=
scanner
.
nextLine
();
if
(
imie
.
isEmpty
())
break
;
lista
.
add
(
imie
);
}
System
.
out
.
println
(
lista
);
System
.
out
.
println
();
System
.
out
.
println
(
"Podawaj numery pozycji, aby je odczytać, a -1 aby zakończyć program."
);
while
(
true
)
{
System
.
out
.
print
(
"Podaj numer: "
);
int
nr
=
scanner
.
nextInt
();
if
(
nr
<
0
)
break
;
if
(
nr
>=
lista
.
size
())
{
System
.
out
.
println
(
"Numer poza tablicą"
);
continue
;
}
System
.
out
.
println
(
"Osoba nr "
+
nr
+
" ma na imię "
+
lista
.
get
(
nr
));
// Dla list także możliwy jest odczyt elementu z określonej pozycji (numeracja od 0).
// Uwaga! Ta operacja jest szybka w przypadku ArrayList, ale wolna w przypadku LinkedList.
}
}
}
\ No newline at end of file
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