-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertStr.java
More file actions
54 lines (35 loc) · 862 Bytes
/
InsertStr.java
File metadata and controls
54 lines (35 loc) · 862 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
53
54
// insert a element in String
import java.util.*;
public class InsertA
{
public static void main(String[] args)
{
int i,p,n;
Scanner sc=new Scanner(System.in);
String s;
System.out.println("Enter the String= ");
s=sc.nextLine();
char a[]=s.toCharArray();
n=a.length;
char temp;
int len=a.length;
System.out.println("Enter the Position Where want to insert Element= ");
p=sc.nextInt();
System.out.println("Enter the Element = " );
char e=sc.next().charAt(0);
/*System.out.println();
System.out.println("Deleted Element= "+a[len-1]);*/
temp=a[len-1];
for(i=len-1;i>p-1;i--)
{
a[i]=a[i-1];
}
a[p-1]=e;
System.out.print("After INsertion of element = ");
for(i=0;i<n;i++)
{
System.out.print(" "+String.valueOf(a[i])+"");
}
System.out.print(" "+temp);
}
}