We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 5941e37 + 4a9a1ff commit 191b634Copy full SHA for 191b634
1 file changed
CountCharacter
@@ -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