Home >>Java Programs >Java Program to count all punctuation characters in the string

Java Program to count all punctuation characters in the string

Java Program to count the total number of punctuation characters exists in a String

In this example, we will see a Java program through which we can count the total number of punctuation characters that exists in a given input string.

Algorithm:
  • STEP 1: START.
  • STEP 2: SET lines= 10.</li>
  • STEP 3: SET space= (lines*2)-2.
  • STEP 4: SET i=1, REPEAT STEP 5 to STEP 18 UNTIL i <= (lines/2).
  • STEP 5: SET flagl=0.
  • STEP 6: SET l=1. REPEAT STEP 7 and 8 UNTIL l <= i.
  • STEP 7: IF flagl is not true PRINT '*' and INCREMENT flagl by 1
    ELSE PRINT "" WITH "*"
  • STEP 8: SET l=l+1.
  • STEP 9: SET l=1.
  • STEP 10: REPEAT STEP 11 UNTIL l <= space.
  • STEP 11: PRINT "" and SET l=l+1.
  • STEP 12: DECREMENT space by 4.
  • STEP 13: SET flagr=0.
  • STEP 14: SET l=1. REPEAT STEP 15 to STEP 16 UNTIL l <= i.
  • STEP 15: IF flag is not true PRINT * and increment flag by 1.
    ELSE PRINT BLANK SPACE " " WITH * .
  • STEP 16: SET l=l+1.
  • STEP 17: PRINT new line.
  • STEP 18: SET i=i+1.
  • STEP 19: INCREMENT space by 4
  • STEP 20: SET i=lines/2.
  • STEP 21: REPEAT STEP 22 to STEP 35 UNTIL i >=1.
  • STEP 22: SET flagl=0.
  • STEP 23: SET l=1. REPEAT STEP 24 and 25 UNTIL l <= i.
  • STEP 24: IF flag is not true PRINT * and INCREMENT flag by 1 ELSE PRINT "" + *
  • STEP 25: SET l=l+1.
  • STEP 26: SET l=1. REPEAT STEP 27 and 28 UNTIL l <= space.
  • STEP 27: PRINT "".
  • STEP 28: SET l = l + 1.
  • STEP 29: INCREMENT space by 4.
  • STEP 30: SET flagr =0.
  • STEP 31: SET l=1. REPEAT STEP 32 to STEP 33 UNTIL l<=i.
  • STEP 32: IF flagr is not true then PRINT * and INCREMENT flagr by 1 else
    PRINT "" with *.
  • STEP 33: SET l=l+1.
  • STEP 34: PRINT new line.
  • STEP 35: SET i= i-1.
  • STEP 36: END.
Program:

class Main
{  
public static void main(String args[])  
{  
int lines=10;  
int space=(lines*2)-2;  
for(int i=1;i<=(lines/2);i++)  
{  
boolean flagl=false;  
for(int l=1;l<=i;l++)  
{  
if(!flagl){  
System.out.print("*");  
flagl=true;  
}  
else  
{  
System.out.print(" ");  
System.out.print("*");  
}  
}  

for(int l=1;l<=space;l++)  
{  
System.out.print(" ");  
}  
space=space-4;  
boolean flagr=false;  
for(int l=1;l<=i;l++)  
{  
if(!flagr){  
System.out.print("*");  
flagr=true;  
}  
else  
{  
System.out.print(" ");  
System.out.print("*");  
}  
}  
System.out.println("");  
}  
space=space+4;  
for(int i=(lines/2);i>=1;i--)  
{  
boolean flagl=false;  
for(int l=1;l<=i;l++)  
{  
if(!flagl){  
System.out.print("*");  
flagl=true;  
}  
else  
{  
System.out.print(" ");  
System.out.print("*");  
}  
}  
for(int l=1;l<=space;l++)  
{  
System.out.print(" ");  
}  
space=space+4;  
boolean flagr=false;  
for(int l=1;l<=i;l++)  
{  
if(!flagr){  
System.out.print("*");  
flagr=true;  
}  
else  
{  
System.out.print(" ");  
System.out.print("*");  
}  
}  
System.out.print("\n");  
}  

}  
}   


Output:
*                  *
* *              * *
* * *          * * *
* * * *      * * * *
* * * * *  * * * * *
* * * * *  * * * * *
* * * *      * * * *
* * *          * * *
* *              * *
*                  *

Java Programs Check Palindrome Number in Java Factorial Program using loop in java Factorial Program using recursion in java Fibonacci Series Program in Java using recursion Fibonacci series without using recursion in Java Find an Armstrong Number in Java Prime Number Program in Java Find Prime numbers between two numbers in Java Break statement in Java for each loop in Java Typecasting in Java Printing the format text with printf in Java How to generate random numbers within a range in Java Java Program to count all punctuation characters in the string Java program to print the following given pattern Java program to print the following given pattern Java program to print the following given pattern Java program to print the following pattern Java program to print the following pattern Java program to print the given pattern Java program to print the given pattern Java program to print the given pattern Java program to print the following pattern Java program to print the following pattern Java Program to Print the following Pattern Java program to print the following pattern Java Program to Print the following Pattern Java Program to print the smallest element in an array Java Program to Print the following pattern Java Program to Print the following pattern Java Program to Print the following Pattern Java Program to Copy One Array to Another in Java Java Program to find the frequency of each element in a array Java Program to left rotate the elements of an array Java Program to print the duplicate elements of an array Java Program to print the elements of an array Java Program for binary search Java Program for linear search Java Program for bubble sort Java Program for insertion sort Java Program for selection sort Java Program to print the elements of an array present on even position Java Program to print the elements of an array in reverse order Java Program to find Third Largest Number in an Array Java Program to print the largest element in an array Print the number of elements in an array java Java Program to print the sum of all the items of the array Java Program to right rotate the elements of an array Java Program to sort the elements of an array in ascending order Java Program to sort the elements of an array in descending order Java Program to print the elements of an array present on odd position Java Program to Check if it is a Sparse Matrix Java Program to check a given matrix is an identity matrix Java Program to determine whether two matrices are equal Java Program to display the lower triangular matrix Java Program to find the product of two matrices