Skip to content

Commit 1ebe496

Browse files
committed
fix bugs in ReverseString(TheAlgorithms#765)
1 parent bdb9acf commit 1ebe496

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Others/RemoveDuplicateFromString.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
public class RemoveDuplicateFromString {
1111
public static void main(String[] args) throws Exception {
1212
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
13-
String inp_str = br.readLine();
13+
String inpStr = br.readLine();
1414

15-
System.out.println("Actual string is: " + inp_str);
16-
System.out.println("String after removing duplicates: " + removeDuplicate(inp_str));
15+
System.out.println("Actual string is: " + inpStr);
16+
System.out.println("String after removing duplicates: " + removeDuplicate(inpStr));
1717

1818
br.close();
1919
}
@@ -32,7 +32,7 @@ public static String removeDuplicate(String s) {
3232
return s;
3333
}
3434

35-
StringBuilder sb = new StringBuilder("");
35+
StringBuilder sb = new StringBuilder();
3636
int n = s.length();
3737

3838
for (int i = 0; i < n; i++) {

Others/ReverseString.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* @author Unknown
1111
*/
12-
class ReverseString {
12+
public class ReverseString {
1313

1414
/**
1515
* This method reverses the string str and returns it
@@ -18,9 +18,9 @@ class ReverseString {
1818
* @return Reversed string
1919
*/
2020
public static String reverse(String str) {
21-
if (str.isEmpty() || str == null) return str;
21+
if (str == null || str.isEmpty()) return str;
2222

23-
char arr[] = str.toCharArray();
23+
char[] arr = str.toCharArray();
2424
for (int i = 0, j = str.length() - 1; i < j; i++, j--) {
2525
char temp = arr[i];
2626
arr[i] = arr[j];
@@ -35,7 +35,7 @@ public static String reverse(String str) {
3535
* @param args Command line arguments
3636
* @throws IOException Exception thrown because of BufferedReader
3737
*/
38-
public static void main(String args[]) throws IOException {
38+
public static void main(String[] args) throws IOException {
3939
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
4040
System.out.println("Enter the string");
4141
String srr = br.readLine();

0 commit comments

Comments
 (0)