forked from divScorp/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColindrome.java
More file actions
56 lines (51 loc) · 1.12 KB
/
Colindrome.java
File metadata and controls
56 lines (51 loc) · 1.12 KB
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
55
56
package String;
import java.util.Scanner;
public class Colindrome {
public static String[] split(String s) {
String t = "";
String r[] = new String[(s.length() / 6)];
for (int i = 0; i < s.length() / 6;) {
for (int j = 0; j < s.length(); j++) {
if ((j + 1) % 6 == 0) {
t += s.charAt(j);
r[i++] = t;
t = "";
} else
t += s.charAt(j);
}
}
for (String x : r) {
System.out.println(x);
}
return r;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String: ");
String s = sc.nextLine();
sc.close();
int flag = 0;
if (s.length() < 6 && (s.length() % 6 != 0))
System.out.println("Not a colindrome!");
String[] res = split(s);
for (int i = 0; i < res.length; i++) {
if (!isColindrome(res[i]))
flag = 1;
}
if (flag == 0) {
System.out.println("String is colindrome");
} else {
System.out.println("Not a colindrome!");
}
}
public static boolean isColindrome(String s) {
int k = 2, j = 3;
while (k > 0) {
if (s.charAt(k) != s.charAt(j))
return false;
k--;
j++;
}
return true;
}
}