Java Program to Count the Total Number of Punctuation Characters Exists in a String17 Mar 2025 | 2 min read In the previous Java string programs, we have counted the number of words, white spaces, vowels, consonants, and characters. Sometimes it also becomes necessary to count the total number of punctuations in a string. So, in this section, we are going to create a Java program that counts the total number of punctuations in a given string. Steps to Count the Punctuations
Let's implement the above steps in a Java program. CountPunctuation.java Output: The number of punctuations exists in the string is: 5 In the above program, we have used a for loop that iterates over the string and executes till the length of the string. For determining the position of the characters in a string, we have used the charAt() method that returns the character at the specified index in a string. For each iteration, each and every character is matched with the punctuation marks by using the == operator. If any character is matched with a punctuation mark the count variable is incremented by 1. At last, we have printed the value of the count variable. Next TopicJava Programs |
In this program, we create a doubly linked list and insert a new node in the middle of list. If list is empty, both head and tail will point to new node. If list is not empty, then we will calculate the size of the...
8 min read
A number is prime if it is divisible by 1 and itself. In other words, a prime number is a natural number with exactly two distinct natural number divisors 1 and itself. For example, 2, 3, 5, 7, 11, etc. are the prime numbers. Note that...
5 min read
A prime number is a number that is greater than 1 and divided by 1 or itself. In other words, prime numbers cannot be divided by other than itself or 1. For example, 2, 3, 5, 7, 11, 13, 17... are the prime numbers. Note: 0 and...
6 min read
In this section, we will write the Java programs to check if a number is positive or negative. We have used the following ways to check the number is positive, negative, or zero. Using Relational Operator Using Math.signum() Method Using Integer.signum() Method Using Bit Shift Operator Using ArrayList class Using Relational Operator To...
5 min read
In this program, we will create a doubly linked list and delete a node from the middle of the list. If the list is empty, display the message "List is empty". If the list is not empty, we will calculate the size of the list...
7 min read
In this program, we need to check whether given matrices are equal or not. Two matrices are said to be equal if and only if they satisfy the following conditions: Both the matrices should have the same number of rows and columns. Both the matrices should have the...
5 min read
In this program, we will create a singly linked list and delete a node from the end of the list. To accomplish this task, we first find out the second last node of the list. Then, make second last node as the new tail of...
6 min read
An array containing various numbers is given. The task is to create different groups, each containing only two elements, such that the difference between the group containing the largest sum and the group containing the lowest sum should be minimum. Note that any element can only...
5 min read
Java Convert Object to String We can convert Object to String in java using toString() method of Object class or String.valueOf(object) method. You can convert any object to String in java whether it is user-defined class, StringBuilder, StringBuffer or anything else. Here, we are going to see two examples...
1 min read
In this program, we will create a singly linked list and delete a node from the beginning of the list. To accomplish this task, we need to make the head pointer pointing to the immediate of the initial node which will now become the...
6 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India