-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComparing_Strings.java
More file actions
50 lines (47 loc) · 982 Bytes
/
Comparing_Strings.java
File metadata and controls
50 lines (47 loc) · 982 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
import java.io.*;
import java.util.*;
public class Comparing_Strings{
static void exec(String a, String b, ArrayList<Integer> list, int l1){
int x=list.get(0);
int y=list.get(1);
char ch1,ch2;
String str="";
ch1=a.charAt(x);
ch2=a.charAt(y);
str = a.substring(0,x)+ch2+a.substring(x+1,y)+ch1+a.substring(y+1);
if(str.equals(b)){
System.out.print("YES");
}else{
System.out.print("NO");
}
}
public static void main(String args[]){
int i,l1,l2;
Scanner sc = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<>();
String a,b,str="";
char cha,chb,ch;
a = sc.nextLine();
b = sc.nextLine();
l1 = a.length();
l2 = b.length();
if(l1==l2){
for(i=0;i<l1;i++){
cha=a.charAt(i);
chb=b.charAt(i);
if(cha!=chb){
list.add(i);
}
}
if(list.size()==2){
exec(a,b,list,l1);
}else{
System.out.print("NO");
System.exit(0);
}
}else{
System.out.print("NO");
System.exit(0);
}
}
}