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
9e0151c9
Commit
9e0151c9
authored
Nov 19, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LosowaTablica
parent
00e7335b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
0 deletions
+56
-0
LosowaTablica.java
src/main/java/p07_tablice/LosowaTablica.java
+56
-0
No files found.
src/main/java/p07_tablice/LosowaTablica.java
0 → 100644
View file @
9e0151c9
package
p07_tablice
;
import
java.util.Arrays
;
import
java.util.Random
;
public
class
LosowaTablica
{
public
static
void
main
(
String
[]
args
)
{
// Utwórz tablicę 21 liczb
int
[]
t
=
new
int
[
21
];
// Wypełnij tablicę losowymi liczbami z zakresu 0-99
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
t
.
length
;
i
++)
{
t
[
i
]
=
random
.
nextInt
(
100
);
}
// Wypisz całą tablicę (Arrays.toString())
System
.
out
.
println
(
Arrays
.
toString
(
t
));
// Oblicz sumę tych liczb
int
suma
=
0
;
for
(
int
element
:
t
)
{
suma
+=
element
;
}
System
.
out
.
println
(
"Suma: "
+
suma
);
// Posortuj tablicę rosnąco i wypisz ponownie (spróbuj znaleźć odp operację)
Arrays
.
sort
(
t
);
System
.
out
.
println
(
Arrays
.
toString
(
t
));
System
.
out
.
println
();
// Wypisz liczby z tej tablicy, ale w takiej kolejności:
// element nr 0, ostatni element, element nr 1, przedostatni element, ...
// aż do wypisania środkowego elementu (tylko jeden raz).
// sposób 1: za pomocą jednej zmiennej i odejmowania
for
(
int
i
=
0
;
i
<
t
.
length
/
2
;
i
++)
{
System
.
out
.
print
(
t
[
i
]
+
" "
);
System
.
out
.
print
(
t
[
t
.
length
-
i
-
1
]
+
" "
);
}
if
(
t
.
length
%
2
==
1
)
{
System
.
out
.
print
(
t
[
t
.
length
/
2
]);
}
System
.
out
.
println
();
for
(
int
i
=
0
,
j
=
t
.
length
-
1
;
i
<
j
;
i
++,
j
--)
{
System
.
out
.
print
(
t
[
i
]
+
" "
);
System
.
out
.
print
(
t
[
j
]
+
" "
);
}
if
(
t
.
length
%
2
==
1
)
{
System
.
out
.
print
(
t
[
t
.
length
/
2
]);
}
System
.
out
.
println
();
}
}
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