fix bugs in ReverseString(#765)
This commit is contained in:
parent
bdb9acfbff
commit
1ebe496737
@ -10,10 +10,10 @@ import java.io.InputStreamReader;
|
|||||||
public class RemoveDuplicateFromString {
|
public class RemoveDuplicateFromString {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||||
String inp_str = br.readLine();
|
String inpStr = br.readLine();
|
||||||
|
|
||||||
System.out.println("Actual string is: " + inp_str);
|
System.out.println("Actual string is: " + inpStr);
|
||||||
System.out.println("String after removing duplicates: " + removeDuplicate(inp_str));
|
System.out.println("String after removing duplicates: " + removeDuplicate(inpStr));
|
||||||
|
|
||||||
br.close();
|
br.close();
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ public class RemoveDuplicateFromString {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder("");
|
StringBuilder sb = new StringBuilder();
|
||||||
int n = s.length();
|
int n = s.length();
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
|
@ -9,7 +9,7 @@ import java.io.InputStreamReader;
|
|||||||
*
|
*
|
||||||
* @author Unknown
|
* @author Unknown
|
||||||
*/
|
*/
|
||||||
class ReverseString {
|
public class ReverseString {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method reverses the string str and returns it
|
* This method reverses the string str and returns it
|
||||||
@ -18,9 +18,9 @@ class ReverseString {
|
|||||||
* @return Reversed string
|
* @return Reversed string
|
||||||
*/
|
*/
|
||||||
public static String reverse(String str) {
|
public static String reverse(String str) {
|
||||||
if (str.isEmpty() || str == null) return str;
|
if (str == null || str.isEmpty()) return str;
|
||||||
|
|
||||||
char arr[] = str.toCharArray();
|
char[] arr = str.toCharArray();
|
||||||
for (int i = 0, j = str.length() - 1; i < j; i++, j--) {
|
for (int i = 0, j = str.length() - 1; i < j; i++, j--) {
|
||||||
char temp = arr[i];
|
char temp = arr[i];
|
||||||
arr[i] = arr[j];
|
arr[i] = arr[j];
|
||||||
@ -35,7 +35,7 @@ class ReverseString {
|
|||||||
* @param args Command line arguments
|
* @param args Command line arguments
|
||||||
* @throws IOException Exception thrown because of BufferedReader
|
* @throws IOException Exception thrown because of BufferedReader
|
||||||
*/
|
*/
|
||||||
public static void main(String args[]) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||||
System.out.println("Enter the string");
|
System.out.println("Enter the string");
|
||||||
String srr = br.readLine();
|
String srr = br.readLine();
|
||||||
|
Loading…
Reference in New Issue
Block a user