forked from Debjit21/Hacktoberfest-22
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prog2.java
52 lines (41 loc) · 1.01 KB
/
Prog2.java
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
package Digital;
import java.util.*;
public class Prog2
{
public static void main(String args[])
{
int n,k;
Scanner sc=new Scanner(System.in);
System.out.print("Enter array size ");
n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
System.out.print("Enter element ");
a[i]=sc.nextInt();
}
System.out.print("Enter k ");
k=sc.nextInt();
if(k>(n-1))
{
k=k%(n-1);
}
int c[]=new int[n];
int p=1;
c[0]=a[0];
for(int i=0;i<k;i++)
{
c[i+1]=a[n-k+i];
}
for(int i=k+1;i<n;i++)
{
c[i]=a[p];
p++;
}
System.out.println("Changed array ");
for(int i=0;i<n;i++)
{
System.out.print(c[i]+", ");
}
}
}