File tree Expand file tree Collapse file tree 1 file changed +38
-2
lines changed
src/com/sbiswas001/twelveproject Expand file tree Collapse file tree 1 file changed +38
-2
lines changed Original file line number Diff line number Diff line change 22
33import java .util .Scanner ;
44
5+ /**
6+ * This class checks if a string is palindrome or not.
7+ * A string is palindrome if it is read same from both sides.
8+ */
59public class PalindromeString {
610
11+ /**
12+ * Stores the string
13+ */
714 private String s ;
815
16+ /**
17+ * Initialises instance variables
18+ */
19+ private PalindromeString () {
20+ s = "" ;
21+ }
22+
23+ /**
24+ * Enters a string from user
25+ */
926 private void input () {
1027 Scanner sc = new Scanner (System .in );
11- System .out .println ("Enter a string: " );
28+ System .out .print ("Enter a string: " );
1229 s = sc .nextLine ();
1330 }
1431
32+ /**
33+ * Checks if string is palindrome or not
34+ * @param x String to be checked
35+ * @return true or false
36+ */
37+ private boolean palindromeCheck (String x ) {
38+ String rev = (new StringBuilder (x )).reverse ().toString ();
39+ return rev .equals (s );
40+ }
41+
42+ /**
43+ * Displays the result
44+ */
45+ private void display () {
46+ System .out .println (palindromeCheck (s ) ?
47+ "String is palindrome." :
48+ "String is not palindrome." );
49+ }
50+
1551 /**
1652 * Calls other methods
1753 * @param args Arguments passed to main method
1854 */
1955 public static void main (String [] args ) {
2056 PalindromeString ob = new PalindromeString ();
2157 ob .input ();
22- System . out . println ();//TODO
58+ ob . display ();
2359 }
2460}
You can’t perform that action at this time.
0 commit comments