Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69f0ea1

Browse files
add removeWhiteSpaces.java
1 parent b985922 commit 69f0ea1

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

‎src/CheckPalindromeString.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
public class CheckPalindromeString {
22

33
boolean checkPalindromeString(String input) {
4-
boolean result = true;
5-
int length = input.length();
6-
for(int i=0; i < length/2; i++) {
7-
if(input.charAt(i) != input.charAt(length-i-1)) {
8-
result = false;
9-
break;
10-
}
11-
}
12-
return result;
4+
boolean result = true;
5+
int length = input.length();
6+
for(int i=0; i < length/2; i++) {
7+
if(input.charAt(i) != input.charAt(length-i-1)) {
8+
result = false;
9+
break;
10+
}
11+
}
12+
return result;
1313
}
1414

1515
public static void main(String[] args) {

‎src/RemoveWhiteSpaces.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class RemoveWhiteSpaces {
2+
3+
String removeWhiteSpaces(String input){
4+
StringBuilder output = new StringBuilder();
5+
6+
char[] charArray = input.toCharArray();
7+
8+
for(char c : charArray) {
9+
if (!Character.isWhitespace(c))
10+
output.append(c);
11+
}
12+
13+
return output.toString();
14+
}
15+
16+
public static void main(String[] args) {
17+
18+
RemoveWhiteSpaces removeWhiteSpaces = new RemoveWhiteSpaces();
19+
20+
String word = "fdkjfkdj kjkjfd ";
21+
22+
System.out.print("remove whitespaces from `");
23+
System.out.print(word);
24+
System.out.print("` to no space `");
25+
System.out.print(removeWhiteSpaces.removeWhiteSpaces("kjkfd kjfkdj "));
26+
System.out.println("`");
27+
}
28+
29+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /