File tree 2 files changed +21
-2
lines changed
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -8,13 +8,11 @@ public static void main(String[] args) {
8
8
9
9
public static String toLowerCase (String str ) {
10
10
char [] chars = str .toCharArray ();
11
-
12
11
for (int i = 0 ; i < chars .length ; ++i ) {
13
12
if (Character .isLetter (chars [i ]) && Character .isUpperCase (chars [i ])) {
14
13
chars [i ] = Character .toLowerCase (chars [i ]);
15
14
}
16
15
}
17
-
18
16
return new String (chars );
19
17
}
20
18
}
Original file line number Diff line number Diff line change
1
+ public class ReverseString {
2
+ public static void main (String [] args ) {
3
+ System .out .println (reverseString ("abc123" ).equals ("321cba" ));
4
+ System .out .println (reverseString ("321cba" ).equals ("abc123" ));
5
+ }
6
+
7
+ public static String reverseString (String str ) {
8
+ if (str == null || str .isEmpty ()) {
9
+ return str ;
10
+ }
11
+ char [] reverseStr = str .toCharArray ();
12
+ for (int i = 0 , j = str .length () - 1 ; i < j ; i ++, j --) {
13
+ char temp = reverseStr [i ];
14
+ reverseStr [i ] = reverseStr [j ];
15
+ reverseStr [j ] = temp ;
16
+ }
17
+ return new String (reverseStr );
18
+ }
19
+ }
20
+
21
+ // java ReverseString.java
You can’t perform that action at this time.
0 commit comments