FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java_Fundamentals/ArrangeNumbersInArray.java at main · devdeepak06/Java_Fundamentals · GitHub
devdeepak06
/
Java_Fundamentals
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java_Fundamentals
/
ArrangeNumbersInArray.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
62 lines (59 loc) · 1.89 KB
Breadcrumbs
Java_Fundamentals
/
ArrangeNumbersInArray.java
Copy path
File metadata and controls
62 lines (59 loc) · 1.89 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//You have been given an empty array(ARR) and its size N. The only input taken from the user will be N and you need not worry about the array.
//Your task is to populate the array using the integers values in the range 1 to N(both inclusive) in the order 1 3 5 ...... 6 4 2.
//Note:
//You need not print the array. You only need to populate it.
//Input Format:
//The first line contains an integer 't' denoting the number of test cases or queries to be run. Then the test cases follow.
//The first and the only line of each test case or query contains an integer 'N'.
//Output Format:
//For each test case, print the elements of the array separated by a single space.
//Output for every test case will be printed in a separate line.
//Constraints:
//1 <= t <= 10^2
//0 <= N <= 10^4
//Time Limit: 1sec
//Sample Input 1:
//1
//6
//Sample Output 1:
//1 3 5 6 4 2
//Sample Input 2:
//2
//9
//4
//Sample Output 2:
//1 3 5 7 9 8 6 4 2
//1 3 4 2
import
java
.
util
.
Scanner
;
public
class
ArrangeNumbersInArray
{
public
static
void
arrange
(
int
[]
arr
,
int
x
) {
int
start
=
0
;
int
end
=
x
-
1
;
int
value
=
1
;
while
(
start
<=
end
) {
arr
[
start
] =
value
;
value
++;
start
++;
if
(
start
<=
end
) {
arr
[
end
] =
value
;
value
++;
end
--;
}
}
}
public
static
void
main
(
String
[]
args
) {
try
(
Scanner
s
=
new
Scanner
(
System
.
in
)) {
int
testCase
=
s
.
nextInt
();
while
(
testCase
>
0
) {
int
n
=
s
.
nextInt
();
int
[]
arr
=
new
int
[
n
];
arrange
(
arr
,
n
);
for
(
int
i
=
0
;
i
<
n
;
i
++) {
System
.
out
.
print
(
arr
[
i
] +
" "
);
}
System
.
out
.
println
();
testCase
--;
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL