-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathString_LCM.java
51 lines (46 loc) · 1.12 KB
/
String_LCM.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
import java.io.*;
import java.lang.*;
import java.util.*;
public class Strings_LCM
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
String t=sc.next();
String temp1=s;
String temp2=t;
while(true)
{
if(temp1.length()==temp2.length())
{
if(temp1.equals(temp2))
{
System.out.println(temp1);
break;
}
else
{
System.out.println(-1);
break;
}
}
if(temp1.length()<temp2.length())
{
temp1=temp1+s;// temp1=temp1+temp1
/*if(temp1.equals(temp2))
{
System.out.println(temp1);
}*/
}
else
{
temp2=temp2+t; //temp2=temp2+temp2
/*if(temp2.equals(temp1))
{
System.out.println(temp2);
}*/
}
}
}
}