-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathProblem_5.java
More file actions
26 lines (20 loc) · 792 Bytes
/
Problem_5.java
File metadata and controls
26 lines (20 loc) · 792 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
package strings;
import java.util.Scanner;
// Problem Title => Write a Code to check whether one string is a rotation of another
public class Problem_5 {
// function to check whether the strings are rotations or not
static boolean areRotations(String str1, String str2) {
return (str1.length() == str2.length() && ((str1 + str2).contains(str2)));
}
// driver function
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str1 = sc.nextLine();
String str2 = sc.nextLine();
if (areRotations(str1, str2))
System.out.println("Strings are rotations of each other");
else
System.out.print("Strings are not rotations of each other");
sc.close();
}
}