-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString15.java
More file actions
47 lines (32 loc) · 819 Bytes
/
String15.java
File metadata and controls
47 lines (32 loc) · 819 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
import java.util.*;
public class String15 {
public static void main(String[] args) {
Scanner str = new Scanner(System.in);
System.out.print("Enter the String : ");
String string = str.nextLine();
System.out.print("Enter the String 2 : ");
String string2 = str.nextLine();
int j=0;
char c;
if (string.length()<string2.length()) {
String swapper = string2;
string2=string;
string=swapper;
}
for (int i=0;i<string.length();i++) {
if (j>=string2.length())
{
c='!';
}
else
c=string2.charAt(j);
if (string.charAt(i)!=c) {
string = string.replace(string.charAt(i), '+');
}else
{
j++;
}
}
System.out.print("Answer : "+string);
}
}