Skip to content

Commit 191b634

Browse files
authored
Merge pull request mayankgb2#9 from mahipal9293/master
CountCharacter.java
2 parents 5941e37 + 4a9a1ff commit 191b634

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

CountCharacter

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class CountCharacter {
2+
public static void main(String[] args) {
3+
String string = "The best of both worlds";
4+
int count = 0;
5+
6+
// Counts each character except space
7+
for (int i = 0; i < string.length(); i++) {
8+
if (string.charAt(i) != ' ')
9+
count++;
10+
}
11+
12+
// Displays the total number of characters present in the given string
13+
System.out.println("Total number of characters in a string: " + count);
14+
}
15+
}

0 commit comments

Comments
 (0)