-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
creating simple program in java to count character in string
- Loading branch information
1 parent
200c851
commit 1be5ae8
Showing
1 changed file
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class CountCharacter | ||
{ | ||
public static void main(String[] args) { | ||
String string = "The best of both worlds"; | ||
int count = 0; | ||
|
||
//Counts each character except space | ||
for(int i = 0; i < string.length(); i++) { | ||
if(string.charAt(i) != ' ') | ||
count++; | ||
} | ||
|
||
//Displays the total number of characters present in the given string | ||
System.out.println("Total number of characters in a string: " + count); | ||
} | ||
} |