-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy patharrayfromPermutation.java
More file actions
32 lines (28 loc) · 952 Bytes
/
arrayfromPermutation.java
File metadata and controls
32 lines (28 loc) · 952 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
public class arrayfromPermutaion
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the number of elements of the array :- ");
int a = in.nextInt();
int[] arr = new int[a];
int[] num = new int[a];
System.out.println("Enter the elements of the array and please make sure the elements are less than " + a);
//Filling the array
for (int i = 0; i < a ; i += 1)
{
arr[i] = in.nextInt();
}
//Building array from permutaion
for(int i = 0; i < a ; i += 1)
{
num[i] = arr[ arr[i] ];
}
System.out.println("The new array created from permutation is :- ");
//Printing the array build from permutation
for(int i = 0; i < a ; i += 1)
{
System.out.print( num[i] + " ");
}
}
}