File tree 1 file changed +20
-25
lines changed 1 file changed +20
-25
lines changed Original file line number Diff line number Diff line change 1
1
class Palindrome {
2
-
3
- private String reverseString (String x ){ //*helper method
4
- String output = "" ;
5
- for (int i =x .length ()-1 ; i >=0 ; i --){
6
- output += x .charAt (i ); //addition of chars create String
7
- }
8
- return output ;
9
- }
10
-
11
-
12
- public Boolean FirstWay (String x ){ //*palindrome method, returns true if palindrome
13
- if (x == null || x .length () <= 1 )
14
- return true ;
15
- return (x .equalsIgnoreCase (reverseString (x )));
16
- }
17
-
18
- public boolean SecondWay (String x )
19
- {
20
- if (x .length () == 0 || x .length () == 1 )
21
- return true ;
22
2
23
- if (x .charAt (0 ) != x .charAt (x .length () - 1 ))
24
- return false ;
3
+ private String reverseString (String x ) { // *helper method
4
+ StringBuilder output = new StringBuilder (x );
5
+ return output .reverse ().toString ();
6
+ }
25
7
26
- return SecondWay (x .substring (1 , x .length () - 1 ));
27
- }
28
- }
8
+ public boolean FirstWay (String x ) { // *palindrome method, returns true if palindrome
9
+ if (x == null || x .length () <= 1 )
10
+ return true ;
11
+ return x .equalsIgnoreCase (reverseString (x ));
12
+ }
13
+
14
+ public boolean SecondWay (String x ) {
15
+ if (x .length () == 0 || x .length () == 1 )
16
+ return true ;
17
+
18
+ if (x .charAt (0 ) != x .charAt (x .length () - 1 ))
19
+ return false ;
20
+
21
+ return SecondWay (x .substring (1 , x .length () - 1 ));
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments