-
Notifications
You must be signed in to change notification settings - Fork 0
/
Student_challenge_18_array_practice_2.java
70 lines (48 loc) · 1.1 KB
/
Student_challenge_18_array_practice_2.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.Scanner;
class Student_challenge_18_array_practice_2
{
public static void main(String [] args)
{
Scanner s = new Scanner(System.in);
int a [] = new int [7];
a[0] = 3;
a[1] = 9;
a[2] = 7;
a[3] = 8;
a[4] = 12;
a[5] = 6;
//printing initial array
System.out.print("initial array :");
System.out.print("[");
for(int x : a)
{
System.out.print(x + ", ");
}
System.out.print("]");
System.out.println(" ");
System.out.println(" ");
System.out.print("from 0 to 5 at which position you want to enter element:");
int index = s.nextInt();
System.out.println(" ");
System.out.print("which element you want to add :");
int t = s.nextInt();
//rotating array and adding elements
System.out.println(" ");
System.out.println("additional elements added :" + t);
for(int i =6; i>index; i--)
{
a[i] = a[i-1];
}
a[index] =t;
System.out.println(" ");
System.out.println(" ");
//printing array after rotation and adding elements
System.out.print("array after rotating and adding elements :");
System.out.print("[");
for(int x : a)
{
System.out.print(x + ", ");
}
System.out.print("]");
}
}