My favorites
▼
|
Sign in
kpi-java-training-6
KPI Java Training fall 2013
Project Home
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
18
attachment: PalindromFinder.java
(946 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
import java.io.*;
public class PalindromFinder {
public static String readLine() {
try {
return new BufferedReader(new InputStreamReader(System.in))
.readLine();
} catch (IOException e) {
return new String();
}
}
public static void main(String[] args) {
System.out.println("Input string:");
String line = readLine();
int lineLength = line.length();
System.out.println("Your string: " + line);
System.out.println("Palindrom in your string: ");
int j;
for (j = 2; j < lineLength+1 ;j++){
for (int i = 0; i+j < lineLength+1; i++){
String substrings = line.substring(i, i + j);
StringBuilder stringBuilder = new StringBuilder(substrings);
if (substrings.equals(stringBuilder.reverse().toString())) {
System.out.println(substrings);
}
}
}
}
}
Powered by
Google Project Hosting