Java program to count the number of holes in a given string
KW.java
Some of the examples are: 8 has 2 holes W has no holes # has 1 hole % has 2 holes 合作 is non-ASCII char ——————————————————————————————————
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW ——————————————————————————————————————————— Program to find number of holes in a string ——————————————————————————————————————————— Enter any string KODINGWINDOW Keyboard characters KODINGWINDOW Number of holes in keyboard characters 4 ——————————————————————————————————————————— kodingwindow@kw:~$ java KW ——————————————————————————————————————————— Program to find number of holes in a string ——————————————————————————————————————————— Enter any string 编码合作WINDOW Keyboard characters WINDOW Number of holes in keyboard characters 2 ——————————————————————————————————————————— kodingwindow@kw:~$ //Removed non-ASCII characters
Java program to count the number of holes in a given number
File: KW.java (count holes in a number)
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW ——————————————————————————————————————————— Program to find number of holes in a number ——————————————————————————————————————————— Enter any number 8789522453 Holes in 8 - 2 Hole in 7 - 0 Holes in 8 - 2 Hole in 9 - 1 Hole in 5 - 0 Hole in 2 - 0 Hole in 2 - 0 Hole in 4 - 1 Hole in 5 - 0 Hole in 3 - 0 Total number of holes in given number is 6 ——————————————————————————————————————————— kodingwindow@kw:~$
What Next?
Java program to find the unique characters from a given string
How to create multiline strings using Java text blocks
Java Arrays
Advertisement