-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.java
More file actions
52 lines (45 loc) · 887 Bytes
/
Copy patharray.java
File metadata and controls
52 lines (45 loc) · 887 Bytes
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
//Problem
//Arrange Numbers in Array
//Send Feedback
//Given a number n, put all elements from 1 to n in an
//array in order - 1,3,.......4,2.
//Input Format :
// Integer n
//Output Format :
// Elements of the array separated by space.
//Sample Input 1 :
//6
//Sample Output 1 :
// 1 3 5 6 4 2
//Sample Input 2 :
//9
//Sample Output 2 :
// 1 3 5 7 9 8 6 4 2
import java.util.Scanner;
public class array {
public static void main(String[] args){
// TODO Auto-generated method stub
Scanner sc=new Scanner (System.in);
int n = sc.nextInt();
int[] arr=new int[n];
int i=0,j=n-1;
int num =1;
while(i<j)
{
arr[i]=num;
i++;
num++;
arr[j]=num;
num++;
j--;
}
if(i==j)
{
arr[i]=num;
}
for (int x=0;x<arr.length;x++)
{
System.out.print(arr[x] + " ");
}
}
}